home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / comms / x_sun_psio / code / sunutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-10  |  1.5 KB  |  68 lines

  1. /* (C) Tim Graves 20th April 1994
  2.    This code is supplied AS IS. no warrantee either expressed or implied 
  3.    is provided. This code may be freeley modified and modified as long as my
  4.    origional authorship is acknowledged. 
  5.    
  6.    Tim Graves
  7.     Sun Microsystems
  8.      
  9.      */
  10. /* this is a set of routines for doing very simple checksums on the sun
  11.  side of things. other unix specifie routines may endup bein installed here */
  12. #include <stdio.h>
  13. #include <fcntl.h>
  14. #include "psion.h" 
  15. static char vsn[] = "@(#) sunutils.c 3.2@(#)" ;
  16. extern int debugcall ;
  17.  
  18. int sunsum (fname)
  19. char * fname ;
  20. {
  21.     int fileid ;
  22.     char buffer[1024];
  23.     int rlen ;
  24.     int crc ;
  25.     
  26.     if (debugcall >= 3)
  27.     {
  28.         fprintf(stderr, "CALL: sunsum (fname = %s)\n", fname) ;
  29.         fflush(stderr) ;
  30.     }
  31.     
  32.     if ((fileid = open (fname, O_RDONLY, 0)) == -1)
  33.     {
  34.         return (BADPARAM) ;
  35.     }
  36.     crc = 0 ;
  37.     while((rlen= read(fileid, &buffer, 1024)) > 0)
  38.        dochksum(&crc,buffer,rlen) ;    
  39.     close(fileid) ;
  40.     return (crc) ;
  41. }
  42.  
  43. dochksum(number, str, len)
  44. int * number ;
  45. int len ;
  46. char * str ;
  47. {
  48.         int i ;
  49.         int res ;
  50.     if (debugcall >= 5)
  51.     {
  52.         fprintf(stderr, "CALL: dochksum (number = 0x%2.2X, str = OMITTED, len = %d)\n", *number, len) ;
  53.         fflush(stderr) ;
  54.     }
  55.         res = *number ;
  56.         for (i = 0 ; i < len ; i ++)
  57.         {
  58.                 res = 0xff & (res + str[i]) ;
  59.         }
  60.         *number = res ;
  61.         if (debugcall >= 5)
  62.         {
  63.             fprintf(stderr, "END: dochksum (number = 0x%2.2X)\n", *number) ;
  64.             fflush(stderr) ;
  65.         }
  66. }
  67.  
  68.