Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
files.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000, Matias Atria
3  *
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.
8  *
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.
13  *
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.
17  */
18 
19 #include <config.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include <sys/stat.h>
23 
24 #include "common.h"
25 
26 char *dgets(Dstring *dstr, FILE *in)
27 {
28  char buffer[256];
29 
30  dstr->length = 0;
31  if(feof(in))
32  return NULL;
33  while(fgets(buffer, 256, in) != NULL) {
34  int len = strlen(buffer);
35 
36  if(buffer[len-1] == '\n') {
37  dstring_append(dstr, buffer, len - 1);
38  break;
39  }
40  dstring_append(dstr, buffer, len);
41  }
42  if(dstr->data)
43  dstr->data[dstr->length] = 0;
44  return dstr->data;
45 }
46 
47 /* some simple helper functions to manipulate file names */
48 
49 const char *file_basename(const char *filename)
50 {
51  const char *ptr = strrchr(filename, '/');
52 
53  return (ptr ? ptr + 1 : filename);
54 }
55 
56 const char *file_extension(const char *filename)
57 {
58  const char *ptr = strchr(file_basename(filename), '.');
59 
60  return (ptr ? ptr + 1 : NULL);
61 }
62 
63 int file_readable(const char *filename)
64 {
65  int status = (access(filename, R_OK) == 0);
66 
67  DEBUG((DBG_FILES, "file_redable(%s) -> %s\n",
68  filename, status ? "Yes" : "No"));
69  return status;
70 }
71 
72 int file_exists(const char *filename)
73 {
74  int status = (access(filename, F_OK) == 0);
75 
76  DEBUG((DBG_FILES, "file_exists(%s) -> %s\n",
77  filename, status ? "Yes" : "No"));
78  return status;
79 }
80