~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_fstream.c

  • Committer: Brian Aker
  • Date: 2008-07-18 22:05:16 UTC
  • Revision ID: brian@tangent.org-20080718220516-dzyjle0iqqjssphx
Dead debug code removal (and a compatible "never used") bit in the
optimizer.

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
 
30
70
 
31
71
/*
32
72
  Write a chunk of bytes to a stream
42
82
    #           Number of bytes written
43
83
*/
44
84
 
45
 
size_t my_fwrite(FILE *stream, const unsigned char *Buffer, size_t Count, myf MyFlags)
 
85
size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags)
46
86
{
47
87
  size_t writtenbytes =0;
48
88
  my_off_t seekptr;
49
89
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
50
 
  uint32_t errors;
 
90
  uint errors;
51
91
#endif
52
92
 
53
93
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
71
111
#ifdef EINTR
72
112
      if (errno == EINTR)
73
113
      {
74
 
        my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
 
114
        VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0)));
75
115
        continue;
76
116
      }
77
117
#endif
84
124
        if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
85
125
          my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
86
126
                   "[stream]",my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
87
 
        sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC);
88
 
        my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
 
127
        VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
 
128
        VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0)));
89
129
        continue;
90
130
      }
91
131
#endif
118
158
  return(fseek(stream, (off_t) pos, whence) ?
119
159
              MY_FILEPOS_ERROR : (my_off_t) ftell(stream));
120
160
} /* 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 */