Listing 7 touch.c — updates time stamp by overwriting old file or creating the file if it doesn't exist

/* touch.c: Update a file's time stamp */

#include <stdio.h>

void touch(char *fname)
{
   FILE *f = fopen(fname,"r+b");
   if (f != NULL)
   {
      char c = getc(f);
      rewind(f);
      putc(c,f);
   }
   else
      fopen(fname,"wb");

   fclose(f);
}

/* End of File */