lib/xfile.c

ソースコードを見る。

関数

int x_setvbuf (XFILE *f, char *buf, int mode, size_t size)
static int x_allocate_buffer (XFILE *f)
XFILEx_fopen (const char *fname, int flags, mode_t mode)
XFILEx_fdup (const XFILE *f)
int x_fclose (XFILE *f)
size_t x_fwrite (const void *p, size_t size, size_t nmemb, XFILE *f)
int x_vfprintf (XFILE *f, const char *format, va_list ap)
int x_fprintf (XFILE *f, const char *format,...)
int x_fileno (const XFILE *f)
int x_fflush (XFILE *f)
void x_setbuffer (XFILE *f, char *buf, size_t size)
void x_setbuf (XFILE *f, char *buf)
void x_setlinebuf (XFILE *f)
int x_feof (XFILE *f)
int x_ferror (XFILE *f)
static void x_fillbuf (XFILE *f)
int x_fgetc (XFILE *f)
size_t x_fread (void *p, size_t size, size_t nmemb, XFILE *f)
char * x_fgets (char *s, int size, XFILE *stream)
off_t x_tseek (XFILE *f, off_t offset, int whence)

変数

static XFILE _x_stdin = { 0, NULL, NULL, XBUFSIZE, 0, O_RDONLY, X_IOFBF, 0 }
static XFILE _x_stdout = { 1, NULL, NULL, XBUFSIZE, 0, O_WRONLY, X_IOLBF, 0 }
static XFILE _x_stderr = { 2, NULL, NULL, 0, 0, O_WRONLY, X_IONBF, 0 }
XFILEx_stdin = &_x_stdin
XFILEx_stdout = &_x_stdout
XFILEx_stderr = &_x_stderr


関数

int x_setvbuf ( XFILE f,
char *  buf,
int  mode,
size_t  size 
)

xfile.c49 行で定義されています。

参照先 XFILE::bufXFILE::bufsizeXFILE::buftypeXFILE::bufusedXFILE::nextXFILE::open_flagsx_fflush().

参照元 x_fdup()x_fopen()x_setbuf()x_setbuffer()x_setlinebuf().

00050 {
00051         if (x_fflush(f) != 0) return -1;
00052         if (f->bufused) return -1;
00053 
00054         /* on files being read full buffering is the only option */
00055         if ((f->open_flags & O_ACCMODE) == O_RDONLY) {
00056                 mode = X_IOFBF;
00057         }
00058 
00059         /* destroy any earlier buffer */
00060         SAFE_FREE(f->buf);
00061         f->buf = 0;
00062         f->bufsize = 0;
00063         f->next = NULL;
00064         f->bufused = 0;
00065         f->buftype = mode;
00066 
00067         if (f->buftype == X_IONBF) return 0;
00068 
00069         /* if buffering then we need some size */
00070         if (size == 0) size = XBUFSIZE;
00071 
00072         f->bufsize = size;
00073         f->bufused = 0;
00074 
00075         return 0;
00076 }

static int x_allocate_buffer ( XFILE f  )  [static]

xfile.c79 行で定義されています。

参照先 XFILE::bufXFILE::bufsizeXFILE::next.

参照元 x_fillbuf()x_fwrite().

00080 {
00081         if (f->buf) return 1;
00082         if (f->bufsize == 0) return 0;
00083         f->buf = (char *)SMB_MALLOC(f->bufsize);
00084         if (!f->buf) return 0;
00085         f->next = f->buf;
00086         return 1;
00087 }

XFILE* x_fopen ( const char *  fname,
int  flags,
mode_t  mode 
)

xfile.c94 行で定義されています。

参照先 errnoXFILE::fdXFILE::open_flagssys_open()x_setvbuf().

参照元 aix_cache_reload()check_log_size()complete_sync()Debug1()do_put()dump_all_namelists()get_credentials_file()initialise_wins()main()map_username()pcap_cache_reload()read_init_file()read_target_host()reopen_logs()startlmhosts()sync_browse_lists()wins_write_database()write_browse_list()writetarheader().

00095 {
00096         XFILE *ret;
00097 
00098         ret = SMB_MALLOC_P(XFILE);
00099         if (!ret) {
00100                 return NULL;
00101         }
00102 
00103         memset(ret, 0, sizeof(XFILE));
00104 
00105         if ((flags & O_ACCMODE) == O_RDWR) {
00106                 /* we don't support RDWR in XFILE - use file 
00107                    descriptors instead */
00108                 SAFE_FREE(ret);
00109                 errno = EINVAL;
00110                 return NULL;
00111         }
00112 
00113         ret->open_flags = flags;
00114 
00115         ret->fd = sys_open(fname, flags, mode);
00116         if (ret->fd == -1) {
00117                 SAFE_FREE(ret);
00118                 return NULL;
00119         }
00120 
00121         x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE);
00122         
00123         return ret;
00124 }

XFILE* x_fdup ( const XFILE f  ) 

xfile.c126 行で定義されています。

参照先 XFILE::fdfdXFILE::open_flagsx_fileno()x_setvbuf().

参照元 main().

00127 {
00128         XFILE *ret;
00129         int fd;
00130 
00131         fd = dup(x_fileno(f));
00132         if (fd < 0) {
00133                 return NULL;
00134         }
00135 
00136         ret = SMB_CALLOC_ARRAY(XFILE, 1);
00137         if (!ret) {
00138                 close(fd);
00139                 return NULL;
00140         }
00141 
00142         ret->fd = fd;
00143         ret->open_flags = f->open_flags;
00144         x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE);
00145         return ret;
00146 }

int x_fclose ( XFILE f  ) 

xfile.c149 行で定義されています。

参照先 XFILE::bufXFILE::bufsizeXFILE::fdx_fflush()x_stderrx_stdinx_stdout.

参照元 aix_cache_reload()complete_sync()do_put()dump_all_namelists()endlmhosts()get_credentials_file()initialise_wins()main()map_username()pcap_cache_reload()read_init_file()read_target_host()reopen_logs()setup_logging()sync_browse_lists()wins_write_database()write_browse_list()writetarheader().

00150 {
00151         int ret;
00152 
00153         /* make sure we flush any buffered data */
00154         (void)x_fflush(f);
00155 
00156         ret = close(f->fd);
00157         f->fd = -1;
00158         if (f->buf) {
00159                 /* make sure data can't leak into a later malloc */
00160                 memset(f->buf, 0, f->bufsize);
00161                 SAFE_FREE(f->buf);
00162         }
00163         /* check the file descriptor given to the function is NOT one of the static
00164          * descriptor of this libreary or we will free unallocated memory
00165          * --sss */
00166         if (f != x_stdin && f != x_stdout && f != x_stderr) {
00167                 SAFE_FREE(f);
00168         }
00169         return ret;
00170 }

size_t x_fwrite ( const void *  p,
size_t  size,
size_t  nmemb,
XFILE f 
)

xfile.c173 行で定義されています。

参照先 XFILE::bufXFILE::bufsizeXFILE::buftypeXFILE::bufusedXFILE::fdtotalx_allocate_buffer()x_fflush().

参照元 x_vfprintf().

00174 {
00175         ssize_t ret;
00176         size_t total=0;
00177 
00178         /* we might be writing unbuffered */
00179         if (f->buftype == X_IONBF || 
00180             (!f->buf && !x_allocate_buffer(f))) {
00181                 ret = write(f->fd, p, size*nmemb);
00182                 if (ret == -1) return -1;
00183                 return ret/size;
00184         } 
00185 
00186 
00187         while (total < size*nmemb) {
00188                 size_t n = f->bufsize - f->bufused;
00189                 n = MIN(n, (size*nmemb)-total);
00190 
00191                 if (n == 0) {
00192                         /* it's full, flush it */
00193                         if (x_fflush(f) != 0) {
00194                                 return -1;
00195                         }
00196                         continue;
00197                 }
00198 
00199                 memcpy(f->buf + f->bufused, total+(const char *)p, n);
00200                 f->bufused += n;
00201                 total += n;
00202         }
00203 
00204         /* when line buffered we need to flush at the last linefeed. This can
00205            flush a bit more than necessary, but that is harmless */
00206         if (f->buftype == X_IOLBF && f->bufused) {
00207                 int i;
00208                 for (i=(size*nmemb)-1; i>=0; i--) {
00209                         if (*(i+(const char *)p) == '\n') {
00210                                 if (x_fflush(f) != 0) {
00211                                         return -1;
00212                                 }
00213                                 break;
00214                         }
00215                 }
00216         }
00217 
00218         return total/size;
00219 }

int x_vfprintf ( XFILE f,
const char *  format,
va_list  ap 
)

xfile.c222 行で定義されています。

参照先 lenvasprintf()x_fwrite().

00223 {
00224         char *p;
00225         int len, ret;
00226         va_list ap2;
00227 
00228         VA_COPY(ap2, ap);
00229 
00230         len = vasprintf(&p, format, ap2);
00231         if (len <= 0) return len;
00232         ret = x_fwrite(p, 1, len, f);
00233         SAFE_FREE(p);
00234         return ret;
00235 }

int x_fprintf ( XFILE f,
const char *  format,
  ... 
)

xfile.c237 行で定義されています。

参照先 x_vfprintf().

00238 {
00239         va_list ap;
00240         int ret;
00241 
00242         va_start(ap, format);
00243         ret = x_vfprintf(f, format, ap);
00244         va_end(ap);
00245         return ret;
00246 }

int x_fileno ( const XFILE f  ) 

xfile.c249 行で定義されています。

参照先 XFILE::fd.

参照元 check_log_size()reopen_logs()smb_readline()smb_readline_replacement()x_fdup().

00250 {
00251         return f->fd;
00252 }

int x_fflush ( XFILE f  ) 

xfile.c255 行で定義されています。

参照先 XFILE::bufXFILE::bufusederrnoXFILE::fdXFILE::flagsXFILE::open_flags.

参照元 dbgflush()Debug1()reopen_logs()setup_logging()smb_readline_replacement()x_fclose()x_fwrite()x_setvbuf()x_tseek().

00256 {
00257         int ret;
00258 
00259         if (f->flags & X_FLAG_ERROR) return -1;
00260 
00261         if (f->bufused == 0 || !f->buf) return 0;
00262 
00263         if ((f->open_flags & O_ACCMODE) != O_WRONLY) {
00264                 errno = EINVAL;
00265                 return -1;
00266         }
00267 
00268         ret = write(f->fd, f->buf, f->bufused);
00269         if (ret == -1) return -1;
00270         
00271         f->bufused -= ret;
00272         if (f->bufused > 0) {
00273                 f->flags |= X_FLAG_ERROR;
00274                 memmove(f->buf, ret + (char *)f->buf, f->bufused);
00275                 return -1;
00276         }
00277 
00278         return 0;
00279 }

void x_setbuffer ( XFILE f,
char *  buf,
size_t  size 
)

xfile.c282 行で定義されています。

参照先 x_setvbuf().

00283 {
00284         x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, size);
00285 }

void x_setbuf ( XFILE f,
char *  buf 
)

xfile.c288 行で定義されています。

参照先 x_setvbuf().

参照元 check_auth_crap()Debug1()main()parse_quota_set()reopen_logs()setup_logging()smbc_init_context()squid_stream().

00289 {
00290         x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, XBUFSIZE);
00291 }

void x_setlinebuf ( XFILE f  ) 

xfile.c294 行で定義されています。

参照先 x_setvbuf().

00295 {
00296         x_setvbuf(f, NULL, X_IOLBF, 0);
00297 }

int x_feof ( XFILE f  ) 

xfile.c301 行で定義されています。

参照先 XFILE::flags.

参照元 complete_sync()do_put()fgets_slash()get_credentials_file()getlmhostsent()initialise_wins().

00302 {
00303         if (f->flags & X_FLAG_EOF) return 1;
00304         return 0;
00305 }

int x_ferror ( XFILE f  ) 

xfile.c308 行で定義されています。

参照先 XFILE::flags.

参照元 getlmhostsent()x_fgets().

00309 {
00310         if (f->flags & X_FLAG_ERROR) return 1;
00311         return 0;
00312 }

static void x_fillbuf ( XFILE f  )  [static]

xfile.c315 行で定義されています。

参照先 XFILE::bufXFILE::bufsizeXFILE::bufusedXFILE::fdXFILE::nextx_allocate_buffer().

参照元 x_fgetc().

00316 {
00317         int n;
00318 
00319         if (f->bufused) return;
00320 
00321         if (!f->buf && !x_allocate_buffer(f)) return;
00322 
00323         n = read(f->fd, f->buf, f->bufsize);
00324         if (n <= 0) return;
00325         f->bufused = n;
00326         f->next = f->buf;
00327 }

int x_fgetc ( XFILE f  ) 

xfile.c330 行で定義されています。

参照先 XFILE::bufusedXFILE::flagsXFILE::nextx_fillbuf().

参照元 x_fgets()x_fread().

00331 {
00332         int ret;
00333 
00334         if (f->flags & (X_FLAG_EOF | X_FLAG_ERROR)) return EOF;
00335         
00336         if (f->bufused == 0) x_fillbuf(f);
00337 
00338         if (f->bufused == 0) {
00339                 f->flags |= X_FLAG_EOF;
00340                 return EOF;
00341         }
00342 
00343         ret = *(unsigned char *)(f->next);
00344         f->next++;
00345         f->bufused--;
00346         return ret;
00347 }

size_t x_fread ( void *  p,
size_t  size,
size_t  nmemb,
XFILE f 
)

xfile.c350 行で定義されています。

参照先 ctotalx_fgetc().

参照元 readfile().

00351 {
00352         size_t total = 0;
00353         while (total < size*nmemb) {
00354                 int c = x_fgetc(f);
00355                 if (c == EOF) break;
00356                 (total+(char *)p)[0] = (char)c;
00357                 total++;
00358         }
00359         return total/size;
00360 }

char* x_fgets ( char *  s,
int  size,
XFILE stream 
)

xfile.c363 行で定義されています。

参照先 cx_ferror()x_fgetc().

参照元 get_credentials_file()read_init_file()read_target_host()smb_readline_replacement()writetarheader().

00364 {
00365         char *s0 = s;
00366         int l = size;
00367         while (l>1) {
00368                 int c = x_fgetc(stream);
00369                 if (c == EOF) break;
00370                 *s++ = (char)c;
00371                 l--;
00372                 if (c == '\n') break;
00373         }
00374         if (l==size || x_ferror(stream)) {
00375                 return 0;
00376         }
00377         *s = 0;
00378         return s0;
00379 }

off_t x_tseek ( XFILE f,
off_t  offset,
int  whence 
)

xfile.c383 行で定義されています。

参照先 XFILE::bufusederrnoXFILE::fdXFILE::flagsXFILE::open_flagssys_lseek()x_fflush().

参照元 do_put().

00384 {
00385         if (f->flags & X_FLAG_ERROR)
00386                 return -1;
00387 
00388         /* only SEEK_SET and SEEK_END are supported */
00389         /* SEEK_CUR needs internal offset counter */
00390         if (whence != SEEK_SET && whence != SEEK_END) {
00391                 f->flags |= X_FLAG_EINVAL;
00392                 errno = EINVAL;
00393                 return -1;
00394         }
00395 
00396         /* empty the buffer */
00397         switch (f->open_flags & O_ACCMODE) {
00398         case O_RDONLY:
00399                 f->bufused = 0;
00400                 break;
00401         case O_WRONLY:
00402                 if (x_fflush(f) != 0)
00403                         return -1;
00404                 break;
00405         default:
00406                 errno = EINVAL;
00407                 return -1;
00408         }
00409 
00410         f->flags &= ~X_FLAG_EOF;
00411         return (off_t)sys_lseek(f->fd, offset, whence);
00412 }


変数

XFILE _x_stdin = { 0, NULL, NULL, XBUFSIZE, 0, O_RDONLY, X_IOFBF, 0 } [static]

xfile.c36 行で定義されています。

XFILE _x_stdout = { 1, NULL, NULL, XBUFSIZE, 0, O_WRONLY, X_IOLBF, 0 } [static]

xfile.c37 行で定義されています。

XFILE _x_stderr = { 2, NULL, NULL, 0, 0, O_WRONLY, X_IONBF, 0 } [static]

xfile.c38 行で定義されています。

XFILE* x_stdin = &_x_stdin

xfile.c40 行で定義されています。

参照元 do_put()smb_readline()smb_readline_replacement()x_fclose().

XFILE* x_stdout = &_x_stdout

xfile.c41 行で定義されています。

参照元 check_auth_crap()main()manage_client_krb5_init()manage_client_krb5_targ()manage_client_ntlmssp_init()manage_client_ntlmssp_request()manage_client_ntlmssp_targ()manage_gss_spnego_client_request()manage_gss_spnego_request()manage_ntlm_change_password_1_request()manage_ntlm_server_1_request()manage_squid_basic_request()manage_squid_ntlmssp_request()offer_gss_spnego_mechs()setup_logging()smb_readline_replacement()squid_stream()x_fclose().

XFILE* x_stderr = &_x_stderr

xfile.c42 行で定義されています。

参照元 main()manage_client_ntlmssp_request()manage_gss_spnego_client_request()manage_squid_request()parse_quota_set()smbc_init_context()squid_stream()writetarheader()x_fclose().


Sambaに対してSat Aug 29 21:23:41 2009に生成されました。  doxygen 1.4.7