©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

c5/x5.c

Go to the documentation of this file.
00001 /*
00002     Environment examples
00003     AUP2, Sec. 5.02
00004 
00005     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00006     May be copied only for purposes and under conditions described
00007     on the Web page www.basepath.com/aup/copyright.htm.
00008 
00009     The Example Files are provided "as is," without any warranty;
00010     without even the implied warranty of merchantability or fitness
00011     for a particular purpose. The author and his publisher are not
00012     responsible for any damages, direct or incidental, resulting
00013     from the use or non-use of these Example Files.
00014 
00015     The Example Files may contain defects, and some contain deliberate
00016     coding mistakes that were included for educational reasons.
00017     You are responsible for determining if and how the Example Files
00018     are to be used.
00019 
00020 */
00021 #include "defs.h"
00022 
00023 #define main main1
00024 
00025 /*[list-environ]*/
00026 extern char **environ;
00027 
00028 int main(void)
00029 {
00030     int i;
00031 
00032     for (i = 0; environ[i] != NULL; i++)
00033         printf("%s\n", environ[i]);
00034     exit(EXIT_SUCCESS);
00035 }
00036 /*[]*/
00037 
00038 #undef main
00039 #define main main2
00040 
00041 /*[getenv]*/
00042 int main(void)
00043 {
00044     char *s;
00045 
00046     s = getenv("LOGNAME");
00047 
00048     if (s == NULL)
00049         printf("variable not found\n");
00050     else
00051         printf("value is \"%s\"\n", s);
00052     exit(EXIT_SUCCESS);
00053 }
00054 /*[]*/
00055 
00056 #undef main
00057 
00058 #include "setenv.h"
00059 
00060 int main(void)
00061 {
00062     int i;
00063 
00064     for (i = 0; environ[i] != NULL; i++)
00065         printf("%s\n", environ[i]);
00066     ec_neg1( setenv("HOME", "abc", true) )
00067     for (i = 0; environ[i] != NULL; i++)
00068         printf("%s\n", environ[i]);
00069     ec_neg1( setenv("HOME", "This is a much larger value", true) )
00070     for (i = 0; environ[i] != NULL; i++)
00071         printf("%s\n", environ[i]);
00072     ec_neg1( setenv("HOME", "fox", false) )
00073     for (i = 0; environ[i] != NULL; i++)
00074         printf("%s\n", environ[i]);
00075     ec_neg1( unsetenv("HOME") )
00076     for (i = 0; environ[i] != NULL; i++)
00077         printf("%s\n", environ[i]);
00078     exit(EXIT_SUCCESS);
00079 
00080 EC_CLEANUP_BGN
00081     exit(EXIT_FAILURE);
00082 EC_CLEANUP_END
00083 }

Generated on Fri Apr 23 10:56:57 2004 for AUP2 Example Source by doxygen 1.3.1