"Fossies" - the Fresh Open Source Software Archive

Member "libpcap-1.9.1/./msdos/bin2c.c" (30 Sep 2019, 891 Bytes) of package /linux/misc/libpcap-1.9.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "bin2c.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.7.4_vs_1.8.0.

    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <stdarg.h>
    4 #include <time.h>
    5 
    6 static void Abort (const char *fmt,...)
    7 {
    8   va_list args;
    9   va_start (args, fmt);
   10   vfprintf (stderr, fmt, args);
   11   va_end (args);
   12   exit (1);
   13 }
   14 
   15 int main (int argc, char **argv)
   16 {
   17   FILE  *inFile;
   18   FILE  *outFile = stdout;
   19   time_t now     = time (NULL);
   20   int    ch, i;
   21 
   22   if (argc != 2)
   23      Abort ("Usage: %s bin-file [> result]", argv[0]);
   24 
   25   if ((inFile = fopen(argv[1],"rb")) == NULL)
   26      Abort ("Cannot open %s\n", argv[1]);
   27 
   28   fprintf (outFile,
   29            "/* data statements for file %s at %.24s */\n"
   30            "/* Generated by BIN2C, G. Vanem 1995 */\n",
   31            argv[1], ctime(&now));
   32 
   33   i = 0;
   34   while ((ch = fgetc(inFile)) != EOF)
   35   {
   36     if (i++ % 12 == 0)
   37        fputs ("\n  ", outFile);
   38     fprintf (outFile, "0x%02X,", ch);
   39   }
   40   fputc ('\n', outFile);
   41   fclose (inFile);
   42   return (0);
   43 }