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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 char *dgets(Dstring *dstr, FILE *in)
32 while(fgets(buffer, 256, in) != NULL) {
33 int len = strlen(buffer);
35 if(buffer[len-1] == '\n') {
36 dstring_append(dstr, buffer, len - 1);
39 dstring_append(dstr, buffer, len);
42 dstr->data[dstr->length] = 0;
46 /* some simple helper functions to manipulate file names */
48 const char *file_basename(const char *filename)
50 const char *ptr = strrchr(filename, '/');
52 return (ptr ? ptr + 1 : filename);
55 const char *file_extension(const char *filename)
57 const char *ptr = strchr(file_basename(filename), '.');
59 return (ptr ? ptr + 1 : NULL);
62 int file_readable(const char *filename)
64 int status = (access(filename, R_OK) == 0);
66 DEBUG((DBG_FILES, "file_redable(%s) -> %s\n",
67 filename, status ? "Yes" : "No"));
71 int file_exists(const char *filename)
73 int status = (access(filename, F_OK) == 0);
75 DEBUG((DBG_FILES, "file_exists(%s) -> %s\n",
76 filename, status ? "Yes" : "No"));