"Fossies" - the Fresh Open Source Software Archive

Member "jpeginfo-1.6.1/misc.c" (10 Dec 2002, 1559 Bytes) of package /linux/privat/old/jpeginfo-1.6.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 "misc.c" see the Fossies "Dox" file reference documentation.

    1 /* misc.c - misc routines for jpeginfo
    2  * $Id: misc.c,v 1.5 2002/12/10 09:58:34 tjko Exp $
    3  *
    4  * Copyright (c) Timo Kokkonen, 1997.
    5  */
    6 
    7 #ifdef HAVE_CONFIG_H
    8 #include "config.h"
    9 #endif
   10 
   11 #include <sys/stat.h>
   12 #include <stdio.h>
   13 #include <stdlib.h>
   14 #include <string.h>
   15 #include <unistd.h>
   16 #include "jpeginfo.h"
   17 
   18 static char *rcsid = "$Id: misc.c,v 1.5 2002/12/10 09:58:34 tjko Exp $";
   19 
   20 
   21 int is_dir(FILE *fp)
   22 {
   23  struct stat buf;
   24  
   25  if (!fp) return 0;
   26  if (fstat(fileno(fp),&buf)) return 0;
   27  if (S_ISDIR(buf.st_mode)) return 1;
   28  return 0;
   29 }
   30 
   31 
   32 long filesize(FILE *fp) 
   33 {
   34   struct stat buf;
   35 
   36   if (!fp) return -1;
   37   if (fstat(fileno(fp),&buf)) return -1;
   38   return buf.st_size;
   39 }
   40 
   41 
   42 void delete_file(char *name, int verbose_mode, int quiet_mode)
   43 {
   44   if (rcsid); /* so the compiler cannot optimize our rcsid string :) */
   45 
   46   if (!name) return;
   47   if (verbose_mode && !quiet_mode) fprintf(stderr,"deleting: %s\n",name);
   48   if (unlink(name) && !quiet_mode) 
   49     fprintf(stderr,"Error unlinking file: %s\n",name);
   50 }
   51 
   52 
   53 char *fgetstr(char *s,int n,FILE *stream) 
   54 {
   55   char *p;
   56   
   57   if (!stream || !s || n < 1) return NULL;
   58   if (!fgets(s,n,stream)) return NULL;
   59   p=&s[strlen(s)-1];
   60   while ((p>=s)&&((*p==10)||(*p==13))) *p--=0;
   61   return s;
   62 }
   63 
   64 
   65 
   66 char *md2str(unsigned char *digest, char *s)
   67 {
   68   int i;
   69   char buf[16],*r;
   70 
   71   if (!digest) return NULL;
   72   if (!s) {
   73     s=(char*)malloc(33);
   74     if (!s) return NULL;
   75   }
   76 
   77   r=s;
   78   for (i = 0; i < 16; i++) {
   79     sprintf (buf,"%02x", digest[i]);
   80     *(s++)=buf[0];
   81     *(s++)=buf[1];
   82   }
   83   *s=0;
   84 
   85   return r;
   86 }
   87 
   88 /* eof :-) */
   89 
   90 
   91 
   92 
   93 
   94