File: env.c

package info (click to toggle)
sbox-dtc 1.11.7-1.1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 340 kB
  • sloc: ansic: 1,290; sh: 414; makefile: 114
file content (54 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download | duplicates (5)
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
#include <stdio.h>
#include <strings.h>
#include <unistd.h>
#include <time.h>
#include <dirent.h>

#define MAXENV 1024
#ifdef PATH_MAX
     #define MAXPATH PATH_MAX
#else
     #define MAXPATH 8192
#endif

static char nm[MAXENV];
static char wd[MAXPATH+1];

int main(int argc, char** argv, char** e) {
  char *name,*delimiter;
  char timestr[1024];
  DIR*    dir;
  struct dirent* dirent;
  time_t now;

  printf("Content-type: text/plain\n\n");

  printf("Arguments:\n");
  printf("argc => %d, argv => ",argc);
  while (argc>0) {
    printf("%s ",*argv++);
    argc--;
  }
  printf("\n\n");

  now = time(NULL);
  strftime(timestr,1024-1,"Localtime: %c %Z\n",localtime(&now));
  puts(timestr);

  printf("Identity:\n");
  printf("uid=%ld, gid=%ld\n\n",(long)getuid(),(long)getgid());

  printf("Current Directory: %s\n\n",getcwd(wd,MAXPATH));

  printf("Environment:\n");

  while ((name = *e++)) {
    delimiter = (char*) strchr(name,'=');
    if (delimiter == 0) continue;
    if (delimiter - name >= MAXENV) continue;
    strncpy(nm,name,delimiter-name);
    nm[delimiter-name]='\0';
    printf("%s => %s\n",nm,++delimiter);
  }
  return 0;
}