|
@@ -55,7 +55,7 @@ int G_getl(char *buf, int n, FILE * fd)
|
|
|
* must be allocated for the string buffer.
|
|
|
*
|
|
|
* \param buf: string buffer to receive read data, at least <i>n</i> must be allocated
|
|
|
- * \param n: number of bytes allocated for buf, at most <i>n - 1</i> are read
|
|
|
+ * \param n: maximum number of bytes to read
|
|
|
* \param fd: file descriptor structure
|
|
|
*
|
|
|
* \return 1 on success
|
|
@@ -67,7 +67,7 @@ int G_getl2(char *buf, int n, FILE * fd)
|
|
|
int c;
|
|
|
int ret = 1;
|
|
|
|
|
|
- while (i < n) {
|
|
|
+ while (i < n - 1) {
|
|
|
c = fgetc(fd);
|
|
|
|
|
|
if (c == EOF) {
|
|
@@ -88,20 +88,12 @@ int G_getl2(char *buf, int n, FILE * fd)
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- if (i < n - 1) {
|
|
|
- buf[i] = c;
|
|
|
- }
|
|
|
|
|
|
- i++;
|
|
|
- }
|
|
|
+ buf[i] = c;
|
|
|
|
|
|
- if (i < n)
|
|
|
- buf[i] = '\0';
|
|
|
- else {
|
|
|
- buf[n - 1] = '\0';
|
|
|
- ret = -1;
|
|
|
+ i++;
|
|
|
}
|
|
|
+ buf[i] = '\0';
|
|
|
|
|
|
return ret;
|
|
|
}
|