fd.c

Go to the documentation of this file.
00001 #include "config.h"
00002 
00003 #include "headers.h"
00004 #include "types.h"
00005 #include "error.h"
00006 #include "fd.h"
00007 
00008 int set_fl(int fd, int flags)
00009 {
00010         int val;
00011 
00012         if ((val = fcntl(fd, F_GETFL, 0)) < 0) {
00013                 print_error(stderr, "fcntl() failed");
00014                 return(1);
00015         }
00016         val |= flags;
00017         if (fcntl(fd, F_SETFL, val) < 0) {
00018                 print_error(stderr, "fcntl() failed");
00019                 return(1);
00020         }
00021         return(0);
00022 }
00023 
00024 int clr_fl(int fd, int flags)
00025 {
00026         int val;
00027 
00028         if ((val = fcntl(fd, F_GETFL, 0)) < 0) {
00029                 print_error(stderr, "fcntl() failed");
00030                 return(1);
00031         }
00032         val &= ~flags;
00033         if (fcntl(fd, F_SETFL, val) < 0) {
00034                 print_error(stderr, "fcntl() failed");
00035                 return(1);
00036         }
00037         return(0);
00038 }
00039 
00040 int fdBegin(int fd)
00041 {
00042         return(set_fl(fd, O_NONBLOCK));
00043 }
00044 
00045 int fdEnd(int fd)
00046 {
00047         return(clr_fl(fd, O_NONBLOCK));
00048 }
00049 
00050 int fdIsFile(int fd)
00051 {
00052         struct stat st;
00053 
00054         if (fstat(fd, &st) != 0) {
00055                 print_error(stderr, "fstat() failed");
00056                 return(0);
00057         }
00058         if (S_ISREG(st.st_mode)) return(1);
00059         return(0);
00060 }
00061 
00062 int fdFileSize(int fd, uint64 *size)
00063 {
00064         struct stat st;
00065 
00066         if (size == 0) {
00067                 print_error(stderr, "size == NULL");
00068                 return(1);
00069         }
00070         if (fstat(fd, &st) != 0) {
00071                 print_error(stderr, "fstat() failed");
00072                 return(1);
00073         }
00074         *size = (uint64)st.st_size;
00075         return(0);
00076 }
00077 

Generated on Thu Jun 28 09:13:03 2007 for bar by  doxygen 1.5.1