File: rogers_example05f.c

package info (click to toggle)
lg-issue39 2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,408 kB
  • ctags: 145
  • sloc: ansic: 207; perl: 72; makefile: 37; sh: 4
file content (69 lines) | stat: -rw-r--r-- 1,518 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>

/*
	This program is written to demonstrate the <stdlib.h> library.
	This program will demonstrate environmental functions of the stdlib library.
	Written by James M. Rogers
	22 March 1999
	Released to the Public Domain on this date.
*/

#define OVERWRITE 1
#define NO_OVERWRITE 0

void shutdown_1 () {
    printf("\nShutting down!\n\n");
}

void shutdown_2 () {
    printf("\nReally Shutting down!\n\n");
}

void shutdown_3 () {
    printf("\nReally Really Shutting down!\n\n");
}

void shutdown_4 () {
    printf("\nReally Really Really Shutting down!\n\n");
}

main(){

    atexit(shutdown_4);

    printf("I am displaying the environmental variable TESTING : ");
    printf("%s\n", getenv("TESTING"));

    printf("The following setenv will only set TESTING if TESTING is unset : ");
    if ( setenv("TESTING", "no_overwite", NO_OVERWRITE) )  {
	abort();
    } else {
	printf("%s\n", getenv("TESTING"));
    }

    atexit(shutdown_3);

    printf("I am unsetting TESTING.\n");
    unsetenv("TESTING");

    printf("The following setenv will only set TESTING if TESTING is unset : ");
    if ( setenv("TESTING", "no_overwite", NO_OVERWRITE) )  {
        abort();
    } else {
        printf("%s\n", getenv("TESTING"));
    }

    atexit(shutdown_2);

    printf("The following setenv will always set TESTING : ");
    if ( setenv("TESTING", "overwrite", OVERWRITE) ) {
	abort();
    } else {
	printf("%s\n", getenv("TESTING"));
    }

    atexit(shutdown_1);

    exit (0);
}