~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_fstream.c

  • Committer: Stewart Smith
  • Date: 2008-09-15 07:13:59 UTC
  • mfrom: (383.1.21 drizzle)
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080915071359-f8bznznyaiqrtqxa
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#define fseek(A,B,C) fseeko((A),(B),(C))
28
28
#endif
29
29
 
30
 
/*
31
 
  Read a chunk of bytes from a FILE
32
 
 
33
 
  SYNOPSIS
34
 
   my_fread()
35
 
   stream       File descriptor
36
 
   Buffer       Buffer to read to
37
 
   Count        Number of bytes to read
38
 
   MyFlags      Flags on what to do on error
39
 
 
40
 
  RETURN
41
 
    (size_t) -1 Error
42
 
    #           Number of bytes read
43
 
 */
44
 
 
45
 
size_t my_fread(FILE *stream, uchar *Buffer, size_t Count, myf MyFlags)
46
 
{
47
 
  size_t readbytes;
48
 
 
49
 
  if ((readbytes= fread(Buffer, sizeof(char), Count, stream)) != Count)
50
 
  {
51
 
    if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
52
 
    {
53
 
      if (ferror(stream))
54
 
        my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
55
 
                 my_filename(fileno(stream)),errno);
56
 
      else
57
 
      if (MyFlags & (MY_NABP | MY_FNABP))
58
 
        my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
59
 
                 my_filename(fileno(stream)),errno);
60
 
    }
61
 
    my_errno=errno ? errno : -1;
62
 
    if (ferror(stream) || MyFlags & (MY_NABP | MY_FNABP))
63
 
      return((size_t) -1);                      /* Return with error */
64
 
  }
65
 
  if (MyFlags & (MY_NABP | MY_FNABP))
66
 
    return(0);                          /* Read ok */
67
 
  return(readbytes);
68
 
} /* my_fread */
69
 
 
70
30
 
71
31
/*
72
32
  Write a chunk of bytes to a stream
158
118
  return(fseek(stream, (off_t) pos, whence) ?
159
119
              MY_FILEPOS_ERROR : (my_off_t) ftell(stream));
160
120
} /* my_seek */
161
 
 
162
 
 
163
 
/* Tell current position of file */
164
 
 
165
 
my_off_t my_ftell(FILE *stream, myf MyFlags __attribute__((unused)))
166
 
{
167
 
  off_t pos;
168
 
  pos=ftell(stream);
169
 
  return((my_off_t) pos);
170
 
} /* my_ftell */