2 * Copyright (C) 2000, Matias Atria
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 char *dgets(Dstring *dstr, FILE *in)
33 while(fgets(buffer, 256, in) != NULL) {
34 int len = strlen(buffer);
36 if(buffer[len-1] == '\n') {
37 dstring_append(dstr, buffer, len - 1);
40 dstring_append(dstr, buffer, len);
43 dstr->data[dstr->length] = 0;
47 /* some simple helper functions to manipulate file names */
49 const char *file_basename(const char *filename)
51 const char *ptr = strrchr(filename, '/');
53 return (ptr ? ptr + 1 : filename);
56 const char *file_extension(const char *filename)
58 const char *ptr = strchr(file_basename(filename), '.');
60 return (ptr ? ptr + 1 : NULL);
63 int file_readable(const char *filename)
65 int status = (access(filename, R_OK) == 0);
67 DEBUG((DBG_FILES, "file_redable(%s) -> %s\n",
68 filename, status ? "Yes" : "No"));
72 int file_exists(const char *filename)
74 int status = (access(filename, F_OK) == 0);
76 DEBUG((DBG_FILES, "file_exists(%s) -> %s\n",
77 filename, status ? "Yes" : "No"));