|
|
| C: A Reference Manual (4th Edition) (ISBN: 0133262243) |
 |
List Price: $44.99
Our Price: $31.49
Used Price: $8.00
Release Date: 05 October, 1994
Manufacturer: Prentice Hall (Paperback)
Sales Rank: 6,413
Author: Samuel P. Harbison, Guy L., Jr. Steele
|
More Info
|
|
|
Check File
|
2001-11-10 18:51:36
|
| |
c
|
|
|
|
|
Category: source:c:files
|
|
Description: Checks the given filename to see if it is a normal file.
|
|
Platform: unix
|
|
Author: detour
|
|
Viewed: 3134
|
|
Rating: 4.8/5 (8 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
/* checkfile.c written by detour@metalshell.com
*
* simple function to check for a file
*
* http://www.metalshell.com/
*
*/
#include <stdio.h>
#include <sys/stat.h>
int isFile(const char *fname);
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s filename\n", argv[0]);
exit(0);
}
if(isFile(argv[1])) {
printf("%s is a file.\n", argv[1]);
}
return 0;
}
int isFile(const char *fname) {
struct stat sbuf;
if (lstat(fname, &sbuf) == -1) {
fprintf(stderr, "lstat() Failed.\n");
return 0;
}
if(S_ISREG(sbuf.st_mode)) {
return 1;
}
return 0;
}
|
|
|