source: rtems/cpukit/libmisc/shell/main_setenv.c @ 0893220

4.104.115
Last change on this file since 0893220 was 0893220, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 12:12:39

Whitespace removal.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 * Set an environment vairable.
3 */
4
5#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <unistd.h>
12#include <string.h>
13#include <errno.h>
14
15#include <rtems.h>
16#include <rtems/shell.h>
17#include "internal.h"
18
19int rtems_shell_main_setenv(int argc, char *argv[])
20{
21  char* env = NULL;
22  char* string = NULL;
23  int   len = 0;
24  int   arg;
25  char* p;
26
27  if (argc <= 2)
28  {
29    printf ("error: no variable or string\n");
30    return 1;
31  }
32
33  env = argv[1];
34
35  for (arg = 2; arg < argc; arg++)
36    len += strlen (argv[arg]);
37
38  len += argc - 2 - 1;
39
40  string = malloc (len + 1);
41
42  if (!string)
43  {
44    printf ("error: no memory\n");
45    return 1;
46  }
47
48  for (arg = 2, p = string; arg < argc; arg++)
49  {
50    strcpy (p, argv[arg]);
51    p += strlen (argv[arg]);
52    if (arg < (argc - 1))
53    {
54      *p = ' ';
55      p++;
56    }
57  }
58
59  if (setenv (env, string, 1) < 0)
60  {
61    printf ("error: %s\n", strerror (errno));
62    return 1;
63  }
64
65  return 0;
66}
67
68rtems_shell_cmd_t rtems_shell_SETENV_Command = {
69  "setenv",                      /* name */
70  "setenv [var] [string]",       /* usage */
71  "misc",                        /* topic */
72  rtems_shell_main_setenv,       /* command */
73  NULL,                          /* alias */
74  NULL                           /* next */
75};
Note: See TracBrowser for help on using the repository browser.