my_lib.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:17k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2.    
  3.    This library is free software; you can redistribute it and/or
  4.    modify it under the terms of the GNU Library General Public
  5.    License as published by the Free Software Foundation; either
  6.    version 2 of the License, or (at your option) any later version.
  7.    
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.    
  13.    You should have received a copy of the GNU Library General Public
  14.    License along with this library; if not, write to the Free
  15.    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  16.    MA 02111-1307, USA */
  17. /* TODO: check for overun of memory for names. */
  18. /*  Convert MSDOS-TIME to standar time_t */
  19. #define USES_TYPES /* sys/types is included */
  20. #include "mysys_priv.h"
  21. #include <m_string.h>
  22. #include <my_dir.h> /* Structs used by my_dir,includes sys/types */
  23. #include "mysys_err.h"
  24. #if defined(HAVE_DIRENT_H)
  25. # include <dirent.h>
  26. # define NAMLEN(dirent) strlen((dirent)->d_name)
  27. #else
  28. # define dirent direct
  29. # define NAMLEN(dirent) (dirent)->d_namlen
  30. # if defined(HAVE_SYS_NDIR_H)
  31. #  include <sys/ndir.h>
  32. # endif
  33. # if defined(HAVE_SYS_DIR_H)
  34. #  include <sys/dir.h>
  35. # endif
  36. # if defined(HAVE_NDIR_H)
  37. #  include <ndir.h>
  38. # endif
  39. # if defined(MSDOS) || defined(__WIN__)
  40. # include <dos.h>
  41. # ifdef __BORLANDC__
  42. # include <dir.h>
  43. # endif
  44. # endif
  45. #endif
  46. #ifdef VMS
  47. #include <rms.h>
  48. #include <iodef.h>
  49. #include <descrip.h>
  50. #endif
  51. #if defined(THREAD) && defined(HAVE_READDIR_R)
  52. #define READDIR(A,B,C) ((errno=readdir_r(A,B,&C)) != 0 || !C)
  53. #else
  54. #define READDIR(A,B,C) (!(C=readdir(A)))
  55. #endif
  56. #define STARTSIZE ONCE_ALLOC_INIT*8  /* some mallocmargin */
  57. static int comp_names(struct fileinfo *a,struct fileinfo *b);
  58. /* We need this because program don't know with malloc we used */
  59. void my_dirend(MY_DIR *buffer)
  60. {
  61.   DBUG_ENTER("my_dirend");
  62.   if (buffer)
  63.     my_free((gptr) buffer,MYF(0));
  64.   DBUG_VOID_RETURN;
  65. } /* my_dirend */
  66. /* Compare in sort of filenames */
  67. static int comp_names(struct fileinfo *a, struct fileinfo *b)
  68. {
  69.   return (strcmp(a->name,b->name));
  70. } /* comp_names */
  71. #if !defined(MSDOS) && !defined(__WIN__)
  72. MY_DIR *my_dir(const char *path, myf MyFlags)
  73. {
  74.   DIR *dirp;
  75.   struct dirent *dp;
  76.   struct fileinfo *fnames;
  77.   char        *buffer, *obuffer, *tempptr;
  78.   uint fcnt,i,size,firstfcnt, maxfcnt,length;
  79.   char tmp_path[FN_REFLEN+1],*tmp_file;
  80.   my_ptrdiff_t diff;
  81.   bool eof;
  82. #ifdef THREAD
  83.   char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1];
  84. #endif
  85.   DBUG_ENTER("my_dir");
  86.   DBUG_PRINT("my",("path: '%s' stat: %d  MyFlags: %d",path,MyFlags));
  87. #if defined(THREAD) && !defined(HAVE_READDIR_R)
  88.   pthread_mutex_lock(&THR_LOCK_open);
  89. #endif
  90.   dirp = opendir(directory_file_name(tmp_path,(my_string) path));
  91.   size = STARTSIZE;
  92.   if (dirp == NULL || ! (buffer = (char *) my_malloc(size, MyFlags)))
  93.     goto error;
  94.   fcnt = 0;
  95.   tmp_file=strend(tmp_path);
  96.   firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) /
  97.     (sizeof(struct fileinfo) + FN_LEN);
  98.   fnames=   (struct fileinfo *) (buffer + sizeof(MY_DIR));
  99.   tempptr = (char *) (fnames + maxfcnt);
  100. #ifdef THREAD
  101.   dp= (struct dirent*) dirent_tmp;
  102. #else
  103.   dp=0;
  104. #endif
  105.   eof=0;
  106.   for (;;)
  107.   {
  108.     while (fcnt < maxfcnt &&
  109.    !(eof= READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
  110.     {
  111.       bzero((gptr) (fnames+fcnt),sizeof(fnames[0])); /* for purify */
  112.       fnames[fcnt].name = tempptr;
  113.       tempptr = strmov(tempptr,dp->d_name) + 1;
  114.       if (MyFlags & MY_WANT_STAT)
  115.       {
  116. VOID(strmov(tmp_file,dp->d_name));
  117. VOID(my_stat(tmp_path, &fnames[fcnt].mystat, MyFlags));
  118.       }
  119.       ++fcnt;
  120.     }
  121.     if (eof)
  122.       break;
  123.     size += STARTSIZE; obuffer = buffer;
  124.     if (!(buffer = (char *) my_realloc((gptr) buffer, size,
  125.        MyFlags | MY_FREE_ON_ERROR)))
  126.       goto error; /* No memory */
  127.     length= (uint) (sizeof(struct fileinfo ) * firstfcnt);
  128.     diff=    PTR_BYTE_DIFF(buffer , obuffer) + (int) length;
  129.     fnames=  (struct fileinfo *) (buffer + sizeof(MY_DIR));
  130.     tempptr= ADD_TO_PTR(tempptr,diff,char*);
  131.     for (i = 0; i < maxfcnt; i++)
  132.       fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*);
  133.     /* move filenames upp a bit */
  134.     maxfcnt += firstfcnt;
  135.     bmove_upp(tempptr,tempptr-length,
  136.       (uint) (tempptr- (char*) (fnames+maxfcnt)));
  137.   }
  138.   (void) closedir(dirp);
  139.   {
  140.     MY_DIR * s = (MY_DIR *) buffer;
  141.     s->number_off_files = (uint) fcnt;
  142.     s->dir_entry = fnames;
  143.   }
  144.   if (!(MyFlags & MY_DONT_SORT))
  145.     qsort((void *) fnames, (size_s) fcnt, sizeof(struct fileinfo),
  146.   (qsort_cmp) comp_names);
  147. #if defined(THREAD) && !defined(HAVE_READDIR_R)
  148.   pthread_mutex_unlock(&THR_LOCK_open);
  149. #endif
  150.   DBUG_RETURN((MY_DIR *) buffer);
  151.  error:
  152. #if defined(THREAD) && !defined(HAVE_READDIR_R)
  153.   pthread_mutex_unlock(&THR_LOCK_open);
  154. #endif
  155.   my_errno=errno;
  156.   if (dirp)
  157.     (void) closedir(dirp);
  158.   if (MyFlags & (MY_FAE+MY_WME))
  159.     my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno);
  160.   DBUG_RETURN((MY_DIR *) NULL);
  161. } /* my_dir */
  162. /*
  163.  * Convert from directory name to filename.
  164.  * On VMS:
  165.  *  xyzzy:[mukesh.emacs] => xyzzy:[mukesh]emacs.dir.1
  166.  *  xyzzy:[mukesh] => xyzzy:[000000]mukesh.dir.1
  167.  * On UNIX, it's simple: just make sure there is a terminating /
  168.  * Returns pointer to dst;
  169.  */
  170. my_string directory_file_name (my_string dst, const char *src)
  171. {
  172. #ifndef VMS
  173.   /* Process as Unix format: just remove test the final slash. */
  174.   my_string end;
  175.   if (src[0] == 0)
  176.     src= (char*) "."; /* Use empty as current */
  177.   end=strmov(dst, src);
  178.   if (end[-1] != FN_LIBCHAR)
  179.   {
  180.     end[0]=FN_LIBCHAR; /* Add last '/' */
  181.     end[1]='';
  182.   }
  183.   return dst;
  184. #else /* VMS */
  185.   long slen;
  186.   long rlen;
  187.   my_string ptr, rptr;
  188.   char bracket;
  189.   struct FAB fab = cc$rms_fab;
  190.   struct NAM nam = cc$rms_nam;
  191.   char esa[NAM$C_MAXRSS];
  192.   if (! src[0])
  193.     src="[.]"; /* Empty is == current dir */
  194.   slen = strlen (src) - 1;
  195.   if (src[slen] == FN_C_AFTER_DIR || src[slen] == FN_C_AFTER_DIR_2 ||
  196.       src[slen] == FN_DEVCHAR)
  197.   {
  198. /* VMS style - convert [x.y.z] to [x.y]z, [x] to [000000]x */
  199.     fab.fab$l_fna = src;
  200.     fab.fab$b_fns = slen + 1;
  201.     fab.fab$l_nam = &nam;
  202.     fab.fab$l_fop = FAB$M_NAM;
  203.     nam.nam$l_esa = esa;
  204.     nam.nam$b_ess = sizeof esa;
  205.     nam.nam$b_nop |= NAM$M_SYNCHK;
  206.     /* We call SYS$PARSE to handle such things as [--] for us. */
  207.     if (SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL)
  208.     {
  209.       slen = nam.nam$b_esl - 1;
  210.       if (esa[slen] == ';' && esa[slen - 1] == '.')
  211. slen -= 2;
  212.       esa[slen + 1] = '';
  213.       src = esa;
  214.     }
  215.     if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2)
  216.     {
  217. /* what about when we have logical_name:???? */
  218.       if (src[slen] == FN_DEVCHAR)
  219.       { /* Xlate logical name and see what we get */
  220. VOID(strmov(dst,src));
  221. dst[slen] = 0; /* remove colon */
  222. if (!(src = getenv (dst)))
  223.   return dst; /* Can't translate */
  224. /* should we jump to the beginning of this procedure?
  225.    Good points: allows us to use logical names that xlate
  226.    to Unix names,
  227.    Bad points: can be a problem if we just translated to a device
  228.    name...
  229.    For now, I'll punt and always expect VMS names, and hope for
  230.    the best! */
  231. slen = strlen (src) - 1;
  232. if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2)
  233. { /* no recursion here! */
  234.   VOID(strmov(dst, src));
  235.   return(dst);
  236. }
  237.       }
  238.       else
  239.       { /* not a directory spec */
  240. VOID(strmov(dst, src));
  241. return(dst);
  242.       }
  243.     }
  244.     bracket = src[slen]; /* End char */
  245.     if (!(ptr = strchr (src, bracket - 2)))
  246.     { /* no opening bracket */
  247.       VOID(strmov (dst, src));
  248.       return dst;
  249.     }
  250.     if (!(rptr = strrchr (src, '.')))
  251.       rptr = ptr;
  252.     slen = rptr - src;
  253.     VOID(strmake (dst, src, slen));
  254.     if (*rptr == '.')
  255.     { /* Put bracket and add */
  256.       dst[slen++] = bracket; /* (rptr+1) after this */
  257.     }
  258.     else
  259.     {
  260.       /* If we have the top-level of a rooted directory (i.e. xx:[000000]),
  261.  then translate the device and recurse. */
  262.       if (dst[slen - 1] == ':'
  263.   && dst[slen - 2] != ':'  /* skip decnet nodes */
  264.   && strcmp(src + slen, "[000000]") == 0)
  265.       {
  266. dst[slen - 1] = '';
  267. if ((ptr = getenv (dst))
  268.     && (rlen = strlen (ptr) - 1) > 0
  269.     && (ptr[rlen] == FN_C_AFTER_DIR || ptr[rlen] == FN_C_AFTER_DIR_2)
  270.     && ptr[rlen - 1] == '.')
  271. {
  272.   VOID(strmov(esa,ptr));
  273.   esa[rlen - 1] = FN_C_AFTER_DIR;
  274.   esa[rlen] = '';
  275.   return (directory_file_name (dst, esa));
  276. }
  277. else
  278.   dst[slen - 1] = ':';
  279.       }
  280.       VOID(strmov(dst+slen,"[000000]"));
  281.       slen += 8;
  282.     }
  283.     VOID(strmov(strmov(dst+slen,rptr+1)-1,".DIR.1"));
  284.     return dst;
  285.   }
  286.   VOID(strmov(dst, src));
  287.   if (dst[slen] == '/' && slen > 1)
  288.     dst[slen] = 0;
  289.   return dst;
  290. #endif /* VMS */
  291. } /* directory_file_name */
  292. #elif defined(WIN32)
  293. /*
  294. *****************************************************************************
  295. ** Read long filename using windows rutines
  296. *****************************************************************************
  297. */
  298. MY_DIR *my_dir(path, MyFlags)
  299. const char *path;
  300. myf MyFlags;
  301. {
  302.   struct fileinfo *fnames;
  303.   char        *buffer, *obuffer, *tempptr;
  304.   int eof,i,fcnt,firstfcnt,length,maxfcnt;
  305.   uint size;
  306. #ifdef __BORLANDC__
  307.   struct ffblk       find;
  308. #else
  309.   struct _finddata_t find;
  310. #endif
  311.   ushort mode;
  312.   char tmp_path[FN_REFLEN],*tmp_file,attrib;
  313.   my_ptrdiff_t diff;
  314. #ifdef _WIN64
  315.   __int64       handle;
  316. #else
  317.   long handle;
  318. #endif
  319.   DBUG_ENTER("my_dir");
  320.   DBUG_PRINT("my",("path: '%s' stat: %d  MyFlags: %d",path,MyFlags));
  321.   /* Put LIB-CHAR as last path-character if not there */
  322.   tmp_file=tmp_path;
  323.   if (!*path)
  324.     *tmp_file++ ='.'; /* From current dir */
  325.   tmp_file= strmov(tmp_file,path);
  326.   if (tmp_file[-1] == FN_DEVCHAR)
  327.     *tmp_file++= '.'; /* From current dev-dir */
  328.   if (tmp_file[-1] != FN_LIBCHAR)
  329.     *tmp_file++ =FN_LIBCHAR;
  330.   tmp_file[0]='*'; /* MSDOS needs this !??? */
  331.   tmp_file[1]='.';
  332.   tmp_file[2]='*';
  333.   tmp_file[3]='';
  334. #ifdef __BORLANDC__
  335.   if ((handle= findfirst(tmp_path,&find,0)) == -1L)
  336.     goto error;
  337. #else
  338.   if ((handle=_findfirst(tmp_path,&find)) == -1L)
  339.     goto error;
  340. #endif
  341.   size = STARTSIZE;
  342.   firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) /
  343.     (sizeof(struct fileinfo) + FN_LEN);
  344.   if ((buffer = (char *) my_malloc(size, MyFlags)) == 0)
  345.     goto error;
  346.   fnames=   (struct fileinfo *) (buffer + sizeof(MY_DIR));
  347.   tempptr = (char *) (fnames + maxfcnt);
  348.   fcnt = 0;
  349.   for (;;)
  350.   {
  351.     do
  352.     {
  353.       fnames[fcnt].name = tempptr;
  354. #ifdef __BORLANDC__
  355.       tempptr = strmov(tempptr,find.ff_name) + 1;
  356.       fnames[fcnt].mystat.st_size=find.ff_fsize;
  357.       fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0;
  358.       mode=MY_S_IREAD; attrib=find.ff_attrib;
  359. #else
  360.       tempptr = strmov(tempptr,find.name) + 1;
  361.       fnames[fcnt].mystat.st_size=find.size;
  362.       fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0;
  363.       mode=MY_S_IREAD; attrib=find.attrib;
  364. #endif
  365.       if (!(attrib & _A_RDONLY))
  366. mode|=MY_S_IWRITE;
  367.       if (attrib & _A_SUBDIR)
  368. mode|=MY_S_IFDIR;
  369.       fnames[fcnt].mystat.st_mode=mode;
  370. #ifdef __BORLANDC__
  371.       fnames[fcnt].mystat.st_mtime=((uint32) find.ff_ftime);
  372. #else
  373.       fnames[fcnt].mystat.st_mtime=((uint32) find.time_write);
  374. #endif
  375.       ++fcnt;
  376. #ifdef __BORLANDC__
  377.     } while ((eof= findnext(&find)) == 0 && fcnt < maxfcnt);
  378. #else
  379.     } while ((eof= _findnext(handle,&find)) == 0 && fcnt < maxfcnt);
  380. #endif
  381.     DBUG_PRINT("test",("eof: %d  errno: %d",eof,errno));
  382.     if (eof)
  383.       break;
  384.     size += STARTSIZE; obuffer = buffer;
  385.     if (!(buffer = (char *) my_realloc((gptr) buffer, size,
  386.        MyFlags | MY_FREE_ON_ERROR)))
  387.       goto error;
  388.     length= sizeof(struct fileinfo ) * firstfcnt;
  389.     diff=    PTR_BYTE_DIFF(buffer , obuffer) +length;
  390.     fnames=  (struct fileinfo *) (buffer + sizeof(MY_DIR));
  391.     tempptr= ADD_TO_PTR(tempptr,diff,char*);
  392.     for (i = 0; i < maxfcnt; i++)
  393.       fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*);
  394.     /* move filenames upp a bit */
  395.     maxfcnt += firstfcnt;
  396.     bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*),
  397.       (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt));
  398.   }
  399.   {
  400.     MY_DIR * s = (MY_DIR *) buffer;
  401.     s->number_off_files = (uint) fcnt;
  402.     s->dir_entry = fnames;
  403.   }
  404.   if (!(MyFlags & MY_DONT_SORT))
  405.     qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names);
  406. #ifndef __BORLANDC__
  407.   _findclose(handle);
  408. #endif
  409.   DBUG_RETURN((MY_DIR *) buffer);
  410. error:
  411.   my_errno=errno;
  412. #ifndef __BORLANDC__
  413.   if (handle != -1)
  414.       _findclose(handle);
  415. #endif
  416.   if (MyFlags & MY_FAE+MY_WME)
  417.     my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno);
  418.   DBUG_RETURN((MY_DIR *) NULL);
  419. } /* my_dir */
  420. #else /* MSDOS and not WIN32 */
  421. /******************************************************************************
  422. ** At MSDOS you always get stat of files, but time is in packed MSDOS-format
  423. ******************************************************************************/
  424. MY_DIR *my_dir(path, MyFlags)
  425. const char *path;
  426. myf MyFlags;
  427. {
  428.   struct fileinfo *fnames;
  429.   char        *buffer, *obuffer, *tempptr;
  430.   int eof,i,fcnt,firstfcnt,length,maxfcnt;
  431.   uint size;
  432.   struct find_t find;
  433.   ushort mode;
  434.   char tmp_path[FN_REFLEN],*tmp_file,attrib;
  435.   my_ptrdiff_t diff;
  436.   DBUG_ENTER("my_dir");
  437.   DBUG_PRINT("my",("path: '%s' stat: %d  MyFlags: %d",path,MyFlags));
  438.   /* Put LIB-CHAR as last path-character if not there */
  439.   tmp_file=tmp_path;
  440.   if (!*path)
  441.     *tmp_file++ ='.'; /* From current dir */
  442.   tmp_file= strmov(tmp_file,path);
  443.   if (tmp_file[-1] == FN_DEVCHAR)
  444.     *tmp_file++= '.'; /* From current dev-dir */
  445.   if (tmp_file[-1] != FN_LIBCHAR)
  446.     *tmp_file++ =FN_LIBCHAR;
  447.   tmp_file[0]='*'; /* MSDOS needs this !??? */
  448.   tmp_file[1]='.';
  449.   tmp_file[2]='*';
  450.   tmp_file[3]='';
  451.   if (_dos_findfirst(tmp_path,_A_NORMAL | _A_SUBDIR, &find))
  452.     goto error;
  453.   size = STARTSIZE;
  454.   firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) /
  455.     (sizeof(struct fileinfo) + FN_LEN);
  456.   if ((buffer = (char *) my_malloc(size, MyFlags)) == 0)
  457.     goto error;
  458.   fnames=   (struct fileinfo *) (buffer + sizeof(MY_DIR));
  459.   tempptr = (char *) (fnames + maxfcnt);
  460.   fcnt = 0;
  461.   for (;;)
  462.   {
  463.     do
  464.     {
  465.       fnames[fcnt].name = tempptr;
  466.       tempptr = strmov(tempptr,find.name) + 1;
  467.       fnames[fcnt].mystat.st_size=find.size;
  468.       fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0;
  469.       mode=MY_S_IREAD; attrib=find.attrib;
  470.       if (!(attrib & _A_RDONLY))
  471. mode|=MY_S_IWRITE;
  472.       if (attrib & _A_SUBDIR)
  473. mode|=MY_S_IFDIR;
  474.       fnames[fcnt].mystat.st_mode=mode;
  475.       fnames[fcnt].mystat.st_mtime=((uint32) find.wr_date << 16) +
  476.      find.wr_time;
  477.       ++fcnt;
  478.     } while ((eof= _dos_findnext(&find)) == 0 && fcnt < maxfcnt);
  479.     DBUG_PRINT("test",("eof: %d  errno: %d",eof,errno));
  480.     if (eof)
  481.       break;
  482.     size += STARTSIZE; obuffer = buffer;
  483.     if (!(buffer = (char *) my_realloc((gptr) buffer, size,
  484.        MyFlags | MY_FREE_ON_ERROR)))
  485.       goto error;
  486.     length= sizeof(struct fileinfo ) * firstfcnt;
  487.     diff=    PTR_BYTE_DIFF(buffer , obuffer) +length;
  488.     fnames=  (struct fileinfo *) (buffer + sizeof(MY_DIR));
  489.     tempptr= ADD_TO_PTR(tempptr,diff,char*);
  490.     for (i = 0; i < maxfcnt; i++)
  491.       fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*);
  492.     /* move filenames upp a bit */
  493.     maxfcnt += firstfcnt;
  494.     bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*),
  495.       (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt));
  496.   }
  497.   {
  498.     MY_DIR * s = (MY_DIR *) buffer;
  499.     s->number_off_files = (uint) fcnt;
  500.     s->dir_entry = fnames;
  501.   }
  502.   if (!(MyFlags & MY_DONT_SORT))
  503.     qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names);
  504.   DBUG_RETURN((MY_DIR *) buffer);
  505. error:
  506.   if (MyFlags & MY_FAE+MY_WME)
  507.     my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno);
  508.   DBUG_RETURN((MY_DIR *) NULL);
  509. } /* my_dir */
  510. #endif /* WIN32 && MSDOS */
  511. /****************************************************************************
  512. ** File status
  513. ** Note that MY_STAT is assumed to be same as struct stat
  514. ****************************************************************************/ 
  515. int my_fstat(int Filedes, MY_STAT *stat_area, myf MyFlags )
  516. {
  517.   DBUG_ENTER("my_fstat");
  518.   DBUG_PRINT("my",("fd: %d MyFlags: %d",Filedes,MyFlags));
  519.   DBUG_RETURN(fstat(Filedes, (struct stat *) stat_area));
  520. }
  521. MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags)
  522. {
  523.   int m_used;
  524.   DBUG_ENTER("my_stat");
  525.   DBUG_PRINT("my", ("path: '%s', stat_area: %lx, MyFlags: %d", path,
  526.      (byte *) stat_area, my_flags));
  527.   if ((m_used= (stat_area == NULL)))
  528.     if (!(stat_area = (MY_STAT *) my_malloc(sizeof(MY_STAT), my_flags)))
  529.       goto error;
  530.   if ( ! stat((my_string) path, (struct stat *) stat_area) )
  531.     DBUG_RETURN(stat_area);
  532.   my_errno=errno;
  533.   if (m_used) /* Free if new area */
  534.     my_free((gptr) stat_area,MYF(0));
  535. error:
  536.   if (my_flags & (MY_FAE+MY_WME))
  537.   {
  538.     my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),path,my_errno);
  539.     DBUG_RETURN((MY_STAT *) NULL);
  540.   }
  541.   DBUG_RETURN((MY_STAT *) NULL);
  542. } /* my_stat */