Deleted Added
sdiff udiff text old ( 171195 ) new ( 171525 )
full compact
1/*-
2 * Copyright (c) 2007 Sean C. Farley <scf@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 19 unchanged lines hidden (view full) ---

28#include <stdbool.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <unistd.h>
33
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/tools/regression/environ/envctl.c 171195 2007-07-04 00:00:41Z scf $");
37
38
39extern char **environ;
40
41
42static void
43dump_environ(void)
44{

--- 4 unchanged lines hidden (view full) ---

49
50 return;
51}
52
53
54static void
55usage(const char *program)
56{
57 fprintf(stderr, "Usage: %s [-DGUcht] [-gu name] [-p name=value] "
58 "[(-S|-s name) value overwrite]\n\n"
59 "Options:\n"
60 " -D\t\t\t\tDump environ\n"
61 " -G name\t\t\tgetenv(NULL)\n"
62 " -S value overwrite\t\tsetenv(NULL, value, overwrite)\n"
63 " -U\t\t\t\tunsetenv(NULL)\n"
64 " -c\t\t\t\tClear environ variable\n"
65 " -g name\t\t\tgetenv(name)\n"
66 " -h\t\t\t\tHelp\n"
67 " -p name=value\t\t\tputenv(name=value)\n"
68 " -s name value overwrite\tsetenv(name, value, overwrite)\n"
69 " -t\t\t\t\tOutput is suitable for testing (no newlines)\n"
70 " -u name\t\t\tunsetenv(name)\n",
71 basename(program));
72
73 return;
74}
75
76
77int
78main(int argc, char **argv)
79{
80 char *cleanEnv[] = { NULL };
81 char arg;
82 const char *eol = "\n";
83 const char *value;
84
85 if (argc == 1) {
86 usage(argv[0]);
87 exit(EXIT_FAILURE);
88 }
89
90 while ((arg = getopt(argc, argv, "DGS:Ucg:hp:s:tu:")) != -1) {
91 switch (arg) {
92 case 'D':
93 errno = 0;
94 dump_environ();
95 break;
96
97 case 'c':
98 environ = cleanEnv;
99 break;
100
101 case 'G':
102 value = getenv(NULL);
103 printf("%s%s", value == NULL ? "" : value, eol);
104 break;
105
106 case 'g':
107 value = getenv(optarg);
108 printf("%s%s", value == NULL ? "" : value, eol);
109 break;
110
111 case 'p':
112 errno = 0;
113 printf("%d %d%s", putenv(optarg), errno, eol);
114 break;
115
116 case 'S':
117 errno = 0;
118 printf("%d %d%s", setenv(NULL, optarg,
119 atoi(argv[optind])), errno, eol);
120 optind += 1;
121 break;
122
123 case 's':

--- 31 unchanged lines hidden ---