00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <config.h>
00017
00018 #include <drizzled/internal/my_sys.h>
00019 #include <drizzled/error.h>
00020 #include <errno.h>
00021
00022 namespace drizzled
00023 {
00024 namespace internal
00025 {
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 size_t my_read(int Filedes, unsigned char *Buffer, size_t Count, myf MyFlags)
00044 {
00045 size_t readbytes, save_count;
00046 save_count= Count;
00047
00048 for (;;)
00049 {
00050 errno= 0;
00051 if ((readbytes= read(Filedes, Buffer, Count)) != Count)
00052 {
00053 errno= errno ? errno : -1;
00054 if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
00055 {
00056 continue;
00057 }
00058 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
00059 {
00060 if (readbytes == (size_t) -1)
00061 my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
00062 "unknown", errno);
00063 else if (MyFlags & (MY_NABP | MY_FNABP))
00064 my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
00065 "unknown", errno);
00066 }
00067 if (readbytes == (size_t) -1 ||
00068 ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
00069 return(MY_FILE_ERROR);
00070 if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO))
00071 {
00072 Buffer+= readbytes;
00073 Count-= readbytes;
00074 continue;
00075 }
00076 }
00077
00078 if (MyFlags & (MY_NABP | MY_FNABP))
00079 readbytes= 0;
00080 else if (MyFlags & MY_FULL_IO)
00081 readbytes= save_count;
00082 break;
00083 }
00084 return(readbytes);
00085 }
00086
00087 }
00088 }