Changeset 131 for trunk/src/sh_files.c


Ignore:
Timestamp:
Oct 22, 2007, 11:19:15 PM (17 years ago)
Author:
rainer
Message:

Use thread-safe libc functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_files.c

    r114 r131  
    6060#if (defined (SH_WITH_CLIENT) || defined (SH_STANDALONE))
    6161
     62#include "sh_pthread.h"
    6263#include "sh_error.h"
    6364#include "sh_utils.h"
     
    191192  SL_RETURN((0), _("sh_files_setrecursion"));
    192193}
    193 
    194194
    195195unsigned long sh_files_chk ()
     
    13401340}
    13411341
     1342/**
    13421343struct sh_dirent {
    1343   /* char               sh_d_name[NAME_MAX + 2]; */
    13441344  char             * sh_d_name;
    13451345  struct sh_dirent * next;
    13461346};
    1347 
    1348 static void kill_sh_dirlist (struct sh_dirent * dirlist)
     1347**/
     1348
     1349void kill_sh_dirlist (struct sh_dirent * dirlist)
    13491350{
    13501351  struct sh_dirent * this;
     
    13621363/* -- add an entry to a directory listing
    13631364 */
    1364 static struct sh_dirent * addto_sh_dirlist (struct dirent * thisEntry,
    1365                                             struct sh_dirent * dirlist)
     1365struct sh_dirent * addto_sh_dirlist (struct dirent * thisEntry,
     1366                                     struct sh_dirent * dirlist)
    13661367{
    13671368  struct sh_dirent * this;
     
    14851486  dir_type        theDir;
    14861487  ShFileType      checkit;
    1487 
     1488  static unsigned int state = 1;
    14881489
    14891490  file_type       theFile;
     
    16331634  /* ---- read ----
    16341635   */
     1636  SH_MUTEX_LOCK(readdir_lock);
     1637
    16351638  do {
    16361639      thisEntry = readdir (thisDir);
     
    16521655  } while (thisEntry != NULL);
    16531656
     1657  SH_MUTEX_UNLOCK(readdir_lock);
     1658
    16541659  closedir (thisDir);
    16551660
     
    16721677
    16731678    BREAKEXIT(sh_derr);
    1674     if (0 == (rand() % 5))
    1675       (void) sh_derr();
     1679
     1680#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_RAND_R)
     1681    if (0 == (rand_r(&state) % 5)) (void) sh_derr();
     1682#else
     1683    if (0 == state * (rand() % 5)) (void) sh_derr();
     1684#endif
    16761685   
    16771686    /* ---- Check the file. ----
     
    19291938  char          * fileName;
    19301939  struct utimbuf  utime_buf;
     1940  static unsigned int state = 1;
    19311941
    19321942  SL_ENTER(_("sh_files_filecheck"));
    19331943
    19341944  BREAKEXIT(sh_derr);
    1935   if (0 == (rand() % 2))
    1936     (void) sh_derr();
     1945
     1946#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_RAND_R)
     1947  if (0 == (rand_r(&state) % 2)) (void) sh_derr();
     1948#else
     1949  if (0 == state * (rand() % 2)) (void) sh_derr();
     1950#endif
    19371951
    19381952  if (dirName && infileName && (dirName[0] == '/') && (dirName[1] == '\0')
Note: See TracChangeset for help on using the changeset viewer.