Mercurial > mplayer.hg
diff gui/util/string.c @ 34560:abcf26dcec6b
Add fgetstr() to read from files without end-of-line characters.
Use it where fgets'ed lines are cleared of EOLs.
Remove gfgets() and replace these calls by fgetstr().
author | ib |
---|---|
date | Fri, 03 Feb 2012 13:38:42 +0000 |
parents | 5a45efc630b8 |
children | ee78c9c66508 |
line wrap: on
line diff
--- a/gui/util/string.c Thu Feb 02 18:26:17 2012 +0000 +++ b/gui/util/string.c Fri Feb 03 13:38:42 2012 +0000 @@ -16,7 +16,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -321,3 +320,26 @@ return fname; } + +/** + * @brief Read characters from @a file. + * + * @note Reading stops with '\\r', '\\n' or EOF. + * + * @param str pointer to a buffer to receive the read characters + * @param size number of characters read at the most (including a terminating null-character) + * @param file file to read from + * + * @return str (success) or NULL (error) + */ +char *fgetstr(char *str, int size, FILE *file) +{ + char *s; + + s = fgets(str, size, file); + + if (s) + s[strcspn(s, "\n\r")] = 0; + + return s; +}