/[path-sandbox]/trunk/src/sandbox_utils.c
Gentoo

Diff of /trunk/src/sandbox_utils.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 279 Revision 280
92 } 92 }
93 93
94 return 0; 94 return 0;
95} 95}
96 96
97#endif /* OUTSIDE_LIBSANDBOX */
98
99int exists(const char *pathname)
100{
101 struct stat buf;
102 int retval;
103
104 if ((NULL == pathname) || (0 == strlen(pathname)))
105 return 0;
106
107 retval = lstat(pathname, &buf);
108 if (-1 != retval)
109 return 1;
110 /* Some or other error occurred */
111 if (ENOENT != errno)
112 return -1;
113
114 return 0;
115}
116
117#ifdef OUTSIDE_LIBSANDBOX
118
119int is_file(const char *pathname)
120{
121 struct stat buf;
122 int retval;
123
124 if ((NULL == pathname) || (0 == strlen(pathname)))
125 return 0;
126
127 retval = lstat(pathname, &buf);
128 if ((-1 != retval) && (S_ISREG(buf.st_mode)))
129 return 1;
130 /* Some or other error occurred */
131 if ((-1 == retval) && (ENOENT != errno))
132 return -1;
133
134 return 0;
135}
136
137int is_dir(const char *pathname, int follow_link)
138{
139 struct stat buf;
140 int retval;
141
142 if ((NULL == pathname) || (0 == strlen(pathname)))
143 return 0;
144
145 retval = follow_link ? stat(pathname, &buf) : lstat(pathname, &buf);
146 if ((-1 != retval) && (S_ISDIR(buf.st_mode)))
147 return 1;
148 /* Some or other error occurred */
149 if ((-1 == retval) && (ENOENT != errno))
150 return -1;
151
152 return 0;
153}
154
155long file_length(int fd) 97long file_length(int fd)
156{ 98{
157 struct stat st; 99 struct stat st;
158 int retval; 100 int retval;
159 101
170{ 112{
171 if ((NULL != env) && (NULL != getenv(env)) && 113 if ((NULL != env) && (NULL != getenv(env)) &&
172 ((0 == strncasecmp(getenv(env), "1", 1)) || 114 ((0 == strncasecmp(getenv(env), "1", 1)) ||
173 (0 == strncasecmp(getenv(env), "true", 4)) || 115 (0 == strncasecmp(getenv(env), "true", 4)) ||
174 (0 == strncasecmp(getenv(env), "yes", 3)))) 116 (0 == strncasecmp(getenv(env), "yes", 3))))
175 return true; 117 return TRUE;
176 118
177 return false; 119 return FALSE;
178} 120}
179 121
180bool is_env_off (const char *env) 122bool is_env_off (const char *env)
181{ 123{
182 if ((NULL != env) && (NULL != getenv(env)) && 124 if ((NULL != env) && (NULL != getenv(env)) &&
183 ((0 == strncasecmp(getenv(env), "0", 1)) || 125 ((0 == strncasecmp(getenv(env), "0", 1)) ||
184 (0 == strncasecmp(getenv(env), "false", 5)) || 126 (0 == strncasecmp(getenv(env), "false", 5)) ||
185 (0 == strncasecmp(getenv(env), "no", 2)))) 127 (0 == strncasecmp(getenv(env), "no", 2))))
186 return true; 128 return TRUE;
187 129
188 return false; 130 return FALSE;
189} 131}
132
133#ifndef OUTSIDE_LIBSANDBOX
190 134
191char * gstrndup (const char *str, size_t size) 135char * gstrndup (const char *str, size_t size)
192{ 136{
193 char *new_str = NULL; 137 char *new_str = NULL;
194 size_t len; 138 size_t len;
220 /* Copied from glibc */ 164 /* Copied from glibc */
221 new_path = strrchr (path, '/'); 165 new_path = strrchr (path, '/');
222 return new_path ? new_path + 1 : (char *) path; 166 return new_path ? new_path + 1 : (char *) path;
223} 167}
224 168
169#endif /* !OUTSIDE_LIBSANDBOX */
225 170
226// vim:noexpandtab noai:cindent ai 171// vim:noexpandtab noai:cindent ai

Legend:
Removed from v.279  
changed lines
  Added in v.280

  ViewVC Help
Powered by ViewVC 1.1.20