home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / xmodem / cr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  778 b   |  47 lines

  1. #
  2. #include <file.h>
  3.  
  4. #define CR    13
  5. #define NL    10
  6.  
  7. char *
  8. LF2CR(file)
  9. char *file; {
  10.     int id, oid;
  11.     char buf[512], *index();
  12.     static char temp[11];
  13.     register char *ptr = buf;
  14.     register ln, count;
  15.  
  16.     strcpy(temp,"tempXXXXXX");
  17.     mktemp(temp);
  18.     if ((oid = open(temp,O_CREAT | O_WRONLY,0644)) < 0) {
  19.         perror(temp);
  20.         unlink(temp);
  21.         exit(-1);
  22.     }
  23.     if ((id = open(file,O_RDONLY,0644)) < 0) {
  24.         perror(file);
  25.         unlink(temp);
  26.         exit(-1);
  27.     }
  28.             
  29.     count = 0;
  30.     while (ln = read(id,ptr,512)) {
  31.         while ( ptr = index(ptr,NL) ) {
  32.             if (ptr > &buf[ln]) break;
  33.             *ptr = CR;
  34.         }
  35.         write(oid,ptr = buf,ln);
  36.         count += ln;
  37.     }
  38.     if (ln = count % 128) {
  39.         count = 128 - ln;
  40.         for (ln = 0, ptr = buf; ln < count ; ln++, *ptr++ = ' ');
  41.         write(oid,buf,ln);
  42.     }
  43.  
  44.     close(oid); close(id);
  45.     return(temp);
  46. }
  47.