#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>

#define MAXENV 1024
#define MAXPATH 8192

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

int main(int argc, char** argv, char** e) {
  char *name,*delimiter;
  char timestr[1024];
  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=%d, gid=%d\n\n",getuid(),getgid());

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

  printf("Environment:\n");

  while ((name = *e++)) {
    delimiter = (char*) index(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;
}
