mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* src/app-utils/file-utils.[ch]: add gnc_getline() function
to read an unlimited line-length from a file (so you're not limited to a buffer size with fgets() and the like). It is similar to the getline(3) on Linux except the API is different and it will always set the return string. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9764 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
1442adfd85
commit
41bbf1ba6b
@ -1,5 +1,11 @@
|
||||
2004-01-12 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
* src/app-utils/file-utils.[ch]: add gnc_getline() function
|
||||
to read an unlimited line-length from a file (so you're
|
||||
not limited to a buffer size with fgets() and the like).
|
||||
It is similar to the getline(3) on Linux except the API
|
||||
is different and it will always set the return string.
|
||||
|
||||
* src/doc/Makefile.am: add new documentation: generic-druid-framework.txt
|
||||
* src/doc/generic-druid-framework.txt: new documentation
|
||||
|
||||
|
@ -128,4 +128,45 @@ gncReadFile (const char * file, char ** data)
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* gnc_getline -- read a line from the input file, up to and including
|
||||
* the newline.
|
||||
*
|
||||
* Args: line - pointer to hold the buffer for the whole line (allocated by
|
||||
* this function)
|
||||
* file - the file from which to read
|
||||
* Return: the number of bytes read
|
||||
*
|
||||
* The caller MUST g_free() the line returned from this call in all
|
||||
* cases where it is non-NULL!
|
||||
*/
|
||||
|
||||
gint64
|
||||
gnc_getline (gchar **line, FILE *file)
|
||||
{
|
||||
char str[BUFSIZ];
|
||||
gint64 len;
|
||||
GString *gs;
|
||||
|
||||
g_return_val_if_fail(line, -1);
|
||||
*line = NULL;
|
||||
g_return_val_if_fail(file, -1);
|
||||
|
||||
gs = g_string_new("");
|
||||
|
||||
while (fgets(str, sizeof(str), file) != NULL) {
|
||||
g_string_append(gs, str);
|
||||
|
||||
len = strlen(str);
|
||||
if (str[len-1] == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
len = gs->len;
|
||||
*line = gs->str;
|
||||
g_string_free(gs, FALSE);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------- END OF FILE --------------------- */
|
||||
|
@ -1,8 +1,9 @@
|
||||
/********************************************************************\
|
||||
* file-utils.h -- simple file utilities *
|
||||
* file-utils.h -- simple file utilities *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1998 Linas Vepstas *
|
||||
* Copyright (C) 1998 Rob Browning *
|
||||
* Copyright (C) 2004 Derek Atkins <derek@ihtfp.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -28,6 +29,8 @@
|
||||
#ifndef GNC_FILE_UTILS_H
|
||||
#define GNC_FILE_UTILS_H
|
||||
|
||||
#include <stdio.h> /* for FILE* */
|
||||
|
||||
char * gncFindFile (const char * filename);
|
||||
|
||||
/********************************************************************\
|
||||
@ -41,4 +44,19 @@ char * gncFindFile (const char * filename);
|
||||
int gncReadFile (const char * file, char ** data);
|
||||
|
||||
|
||||
/**
|
||||
* gnc_getline -- read a line from the input file, up to and including
|
||||
* the newline.
|
||||
*
|
||||
* Args: line - pointer to hold the buffer for the whole line (allocated by
|
||||
* this function)
|
||||
* file - the file from which to read
|
||||
* Return: the number of bytes read
|
||||
*
|
||||
* The caller MUST g_free() the line returned from this call in all
|
||||
* cases where it is non-NULL!
|
||||
*/
|
||||
gint64 gnc_getline (gchar **line, FILE *file);
|
||||
|
||||
|
||||
#endif /* GNC_FILE_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user