TPCCLIB
Loading...
Searching...
No Matches
filexist.c
Go to the documentation of this file.
1
4/*****************************************************************************/
5#include "tpcclibConfig.h"
6/*****************************************************************************/
7#include "tpcextensions.h"
8/*****************************************************************************/
9#include "tpcfileutil.h"
10/*****************************************************************************/
11
12/*****************************************************************************/
19 const char *filename
20) {
21 if(filename==NULL || strnlen(filename, 2)<1) return(0);
22 struct stat fst;
23 if(stat(filename, &fst)!=0) return(0);
24 if(S_ISREG(fst.st_mode)) return(1);
25 return(0);
26}
27/*****************************************************************************/
28
29/*****************************************************************************/
33unsigned short int pathFileNr(
35 const char *pathname
36) {
37 if(pathname==NULL || strnlen(pathname, 2)<1) return(0);
38 /* Check that path exists */
39 if(!pathExist(pathname)) return(0);
40 /* Open the directory */
41 DIR *dp;
42 dp=opendir(pathname); if(dp==NULL) return(0);
43#if(1)
44 char tempname[2*FILENAME_MAX];
45 unsigned short int n=0;
46 struct dirent *de;
47 /* Go through the directory */
48 while((de=readdir(dp))!=NULL) {
49 //printf("d_name='%s'\n", de.d_name);
50 if(de->d_name[0]=='.') continue; /* Ignore hidden and 'system' dirs */
51 /* Combine path and name */
52 sprintf(tempname, "%s/%s", pathname, de->d_name);
53 //printf("name='%s'\n", tempname);
54 /* Check that it is regular file */
55 if(fileExist(tempname)) n++;
56 }
57#else // readdir_r deprecated
58 struct dirent de, *deptr;
59 char tempname[2*FILENAME_MAX];
60 unsigned short int n=0;
61 /* Go through the directory */
62 while(readdir_r(dp, &de, &deptr)==0 && deptr!=NULL) {
63 //printf("d_name='%s'\n", de.d_name);
64 if(de.d_name[0]=='.') continue; /* Ignore hidden and 'system' dirs */
65 /* Combine path and name */
66 sprintf(tempname, "%s/%s", pathname, de.d_name);
67 //printf("name='%s'\n", tempname);
68 /* Check that it is regular file */
69 if(fileExist(tempname)) n++;
70 }
71#endif
72 closedir(dp);
73 return(n);
74}
75/*****************************************************************************/
76
77/*****************************************************************************/
83unsigned short int pathFileList(
85 const char *pathname,
87 IFT *ift
88) {
89 if(pathname==NULL || strnlen(pathname, 2)<1) return(0);
90 if(ift==NULL) return(0);
91 /* Check that path exists */
92 if(!pathExist(pathname)) return(0);
93 /* Open the directory */
94 DIR *dp;
95 dp=opendir(pathname); if(dp==NULL) return(0);
96#if(1)
97 char tempname[2*FILENAME_MAX];
98 unsigned short int n=0;
99 struct dirent *de;
100 /* Go throught the directory */
101 while((de=readdir(dp))!=NULL) {
102 if(de->d_name[0]=='.') continue; /* Ignore hidden and 'system' dirs */
103 /* Combine path and name */
104 sprintf(tempname, "%s/%s", pathname, de->d_name);
105 /* Check that it is regular file */
106 if(!fileExist(tempname)) continue;
107 /* Add to IFT */
108 if(iftPut(ift, NULL, tempname, 0, NULL)) break;
109 n++;
110 }
111#else // readdir_r deprecated
112 struct dirent de, *deptr;
113 char tempname[2*FILENAME_MAX];
114 unsigned short int n=0;
115 /* Go throught the directory */
116 while(readdir_r(dp, &de, &deptr)==0 && deptr!=NULL) {
117 if(de.d_name[0]=='.') continue; /* Ignore hidden and 'system' dirs */
118 /* Combine path and name */
119 sprintf(tempname, "%s/%s", pathname, de.d_name);
120 /* Check that it is regular file */
121 if(!fileExist(tempname)) continue;
122 /* Add to IFT */
123 if(iftPut(ift, NULL, tempname, 0, NULL)) break;
124 n++;
125 }
126#endif
127 closedir(dp);
128 return(n);
129}
130/*****************************************************************************/
131
132/*****************************************************************************/
unsigned short int pathFileNr(const char *pathname)
Definition filexist.c:33
unsigned short int pathFileList(const char *pathname, IFT *ift)
Definition filexist.c:83
int fileExist(const char *filename)
Definition filexist.c:17
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
Definition ift.c:63
int pathExist(const char *pathname)
Definition pathexist.c:17
size_t strnlen(const char *s, size_t n)
Definition stringext.c:566
Definition tpcift.h:43
Header file for library libtpcextensions.
Header file for libtpcfileutil.