home *** CD-ROM | disk | FTP | other *** search
- /* (C) Tim Graves 20th April 1994
- This code is supplied AS IS. no warrantee either expressed or implied
- is provided. This code may be freeley modified and modified as long as my
- origional authorship is acknowledged.
-
- Tim Graves
- Sun Microsystems
-
- */
- /* this is a set of routines for doing very simple checksums on the sun
- side of things. other unix specifie routines may endup bein installed here */
- #include <stdio.h>
- #include <fcntl.h>
- #include "psion.h"
- static char vsn[] = "@(#) sunutils.c 3.2@(#)" ;
- extern int debugcall ;
-
- int sunsum (fname)
- char * fname ;
- {
- int fileid ;
- char buffer[1024];
- int rlen ;
- int crc ;
-
- if (debugcall >= 3)
- {
- fprintf(stderr, "CALL: sunsum (fname = %s)\n", fname) ;
- fflush(stderr) ;
- }
-
- if ((fileid = open (fname, O_RDONLY, 0)) == -1)
- {
- return (BADPARAM) ;
- }
- crc = 0 ;
- while((rlen= read(fileid, &buffer, 1024)) > 0)
- dochksum(&crc,buffer,rlen) ;
- close(fileid) ;
- return (crc) ;
- }
-
- dochksum(number, str, len)
- int * number ;
- int len ;
- char * str ;
- {
- int i ;
- int res ;
- if (debugcall >= 5)
- {
- fprintf(stderr, "CALL: dochksum (number = 0x%2.2X, str = OMITTED, len = %d)\n", *number, len) ;
- fflush(stderr) ;
- }
- res = *number ;
- for (i = 0 ; i < len ; i ++)
- {
- res = 0xff & (res + str[i]) ;
- }
- *number = res ;
- if (debugcall >= 5)
- {
- fprintf(stderr, "END: dochksum (number = 0x%2.2X)\n", *number) ;
- fflush(stderr) ;
- }
- }
-
-