Category : OS/2 Files
Archive   : EMXLIB8F.ZIP
Filename : CRLF.C

 
Output of file : CRLF.C contained in archive : EMXLIB8F.ZIP
/* crlf.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */

#include
#include

/* Do CR/LF -> LF conversion in the buffer BUF containing SIZE characters. */
/* Store the number of resulting characters to *NEW_SIZE. This value does */
/* not include the final CR, if present. If the buffer ends with CR, 1 is */
/* returned, 0 otherwise. */

int _crlf (char *buf, size_t size, size_t *new_size)
{
size_t src, dst;
char *p;

p = memchr (buf, '\r', size); /* Avoid copying until CR reached */
if (p == NULL) /* This is the trivial case */
{
*new_size = size;
return (0);
}
src = dst = p - buf; /* Start copying here */
while (src < size)
{
if (buf[src] == '\r') /* CR? */
{
++src; /* Skip the CR */
if (src >= size) /* Is it the final char? */
{
*new_size = dst; /* Yes -> don't include in new_size, */
return (1); /* notify caller */
}
if (buf[src] != '\n') /* CR not followed by LF? */
--src; /* Yes -> copy the CR */
}
buf[dst++] = buf[src++]; /* Copy a character */
}
*new_size = dst;
return (0);
}


  3 Responses to “Category : OS/2 Files
Archive   : EMXLIB8F.ZIP
Filename : CRLF.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/