2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 1999, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2008 , Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "defines.h"
|
2008-01-05 18:53:22 +05:30
|
|
|
#include "prototypes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 17:24:30 +05:30
|
|
|
/*@null@*/char *fgetsx (/*@returned@*/ /*@out@*/char *buf, int cnt, FILE * f)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
char *cp = buf;
|
|
|
|
char *ep;
|
|
|
|
|
|
|
|
while (cnt > 0) {
|
2009-06-13 01:50:45 +05:30
|
|
|
if (fgets (cp, cnt, f) != cp) {
|
2008-05-26 06:29:42 +05:30
|
|
|
if (cp == buf) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2008-05-26 06:29:42 +05:30
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-05-26 06:29:42 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-05-26 06:29:42 +05:30
|
|
|
ep = strrchr (cp, '\\');
|
|
|
|
if ((NULL != ep) && (*(ep + 1) == '\n')) {
|
|
|
|
cnt -= ep - cp;
|
|
|
|
if (cnt > 0) {
|
|
|
|
cp = ep;
|
|
|
|
*cp = '\0';
|
|
|
|
}
|
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-05-26 06:29:42 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int fputsx (const char *s, FILE * stream)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-05-26 06:29:42 +05:30
|
|
|
for (i = 0; '\0' != *s; i++, s++) {
|
|
|
|
if (putc (*s, stream) == EOF) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return EOF;
|
2008-05-26 06:29:42 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
#if 0 /* The standard getgr*() can't handle that. --marekm */
|
|
|
|
if (i > (BUFSIZ / 2)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
if (putc ('\\', stream) == EOF ||
|
|
|
|
putc ('\n', stream) == EOF)
|
|
|
|
return EOF;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-26 06:29:42 +05:30
|
|
|
|