/* * disk2byte.c * * function reads an unsigned char (byte) image from disk * * * jph 15 June 1992 */ #include #include #include #include #include #define BYTE unsigned char void disk2byte(x,row_dim,col_dim,fn) BYTE *x; /* image to be written */ int row_dim; /* row dimension of x */ int col_dim; /* col dimension of x */ char *fn; /* filename */ { int fd; /* file descriptor */ int n_bytes; /* number of bytes to read */ /* * detect zero dimension input */ if ((row_dim==0) || (col_dim==0)) return; /* * create and open the file */ if ((fd = open(fn, O_RDONLY))==-1) { printf("\ndisk2byte.c : could not open %s !",fn); return; } /* * read image data from the file */ n_bytes = row_dim * col_dim * sizeof(unsigned char); if (read(fd,x,n_bytes) != n_bytes) { printf("\ndisk2byte.c : complete read of %s did not succeed.",fn); } /* * close file and return */ if (close(fd) == -1) printf("\ndisk2byte.c : error closing %s.",fn); return; }