💾 Archived View for home.tobot.dev › cgi › date.c captured on 2022-03-01 at 15:12:51.

View Raw

More Information

-=-=-=-=-=-=-

#include "./std.h"

// Uncomment to disable inlining
// #define inline

void print_header()
{
  print("20 text/gemini\r\n# Hello, C!\r\nThis page was generated from "
        "C code (without any libraries like glibc!)");
}

void print_argv(int const argc, char const * const * const argv)
{
  if(argc > 0)
  {
    print("\r\n## argv:");
    for(int i = 0; i < argc; i++)
    {
      print("\r\n");
      print(argv[i]);
    }
  }
}

void print_envp(char const * const * const envp)
{
  if(envp[0] != 0)
  {
    print("\r\n## envp:");
    unsigned char i = 0;
    while(envp[i] != 0 && i < 254)
    {
      print("\r\n");
      print(envp[i]);
      i++;
    }
  }
}

void print_footer()
{
  struct timeval tv;
  struct timezone tz;

  struct timeval *restrict tvp = &tv;
  struct timezone *restrict tzp = &tz;

  gettimeofday(tvp, tzp);

  char str[64];
  print("\r\n\r\n### This page was generated at: ");
  print(itoa(tv.tc_sec, str));
  print("s ");
  print(itoa(tv.tv_usec, str));
  print("us");
}

int main(int const argc,
         char const * const * const argv,
         char const * const * const envp) {
  print_header();
  print_argv(argc, argv);
  print_envp(envp);
  print_footer();

  return 0;
}