Sponsored Content
Full Discussion: scandir() and threads
Top Forums Programming scandir() and threads Post 302441121 by jim mcnamara on Thursday 29th of July 2010 10:19:26 AM
Old 07-29-2010
scandir() is supposed to be threadsafe on POSIX-compliant systems
Here is a list of those that are not threadsafe from unix.org:

Code:
Thread-safety


The following functions are not guaranteed to be thread-safe on all UNIX systems: 

asctime()  basename()  catgets()  ctime()  
dbm_clearerr()  dbm_close()  dbm_delete()  dbm_error()  
dbm_fetch()  dbm_firstkey()  dbm_nextkey()  dbm_open()  
dbm_store()  dirname()  drand48()  ecvt()  
encrypt()  endgrent()  endpwent()  endutxent()  
fcvt()  gamma()  gcvt()  getc_unlocked()  
getchar_unlocked()  getdate()  getenv()  getgrent()  
getgrgid()  getgrnam()  getlogin()  getopt()  
getpwnam()  getpwent()  getpwuid()  getutxent()  
getutxid()  getutxline()  getw()  gmtime()  
l64a()  lgamma()  lrand48()  localtime()  
mrand48()  nl_langinfo()  ptsname()  putc_unlocked()  
putchar_unlocked()  putenv()  pututxline()  rand()  
readdir()  setgrent()  setkey()  setpwent()  
setutxent()  strerror()  strtok()  ttyname()  



The functions ctermid() and tmpnam() need not be thread-safe if passed a NULL argument.

 

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

old threads

Neo, if I have an old thread that is a few months old, and a few pages back in the forum it was posted in, is it ok to 'bump' it back to the front? or, would you rather i deleted the old thread, and just create a new one? btw the thread has no replies. (2 Replies)
Discussion started by: norsk hedensk
2 Replies

2. Programming

Need help with scandir / stat

I'm writing a file manager program using FC3 and C, and I'm having a problem displaying the stat info of subdirectories. #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> int main() { char *dirname = "mydirectory"; struct dirent **namelist; ... (2 Replies)
Discussion started by: Bertsura
2 Replies

3. UNIX for Dummies Questions & Answers

threads

i am tring to sort lots of data thats in many columns by just one column but, if I use sort +16 inputfile the column fluctuates because some of the rows have spaces etc within the text, so the end result is just a mess as it jumps around the columns depending whether it has spaces or not ....ie... (2 Replies)
Discussion started by: Gerry405
2 Replies

4. Programming

scandir() for Solaris

I'd like to use scandir() on solaris, but it doesn't find sys/dir.h What do you think I should do? thanks (2 Replies)
Discussion started by: nadiamihu
2 Replies

5. Solaris

threads

Hi all! 1)Is there a way to write a program that will work on both solaris and intel based machines. 2)How can I achive this for a program that creates and synchronizes three threads. Thank you. vij. (3 Replies)
Discussion started by: vijlak
3 Replies

6. UNIX for Advanced & Expert Users

How many threads do I use ?

Hi, I have a program that has two types of threads: 1) Reader threads 2) Worker Threads Readers: Their only job is to read files. They just read data from the files and put them into a buffer. They are obviously I/O intensive. Workers: These are CPU intensive. They do some computation... (5 Replies)
Discussion started by: the_learner
5 Replies

7. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

8. Programming

scandir() + windows equivalent

Currently, Im trying to redesign some Unix-based C code to work on the Windows operating system and one problem I ran into when compiling was that the compiler failed to recognise scandir() (from my original Linux code) Im aware that scandir() is a Unix-based function, so is there an equivalent... (1 Reply)
Discussion started by: JamesGoh
1 Replies

9. Programming

Threads help

Hello! I started studying studying about POSIX Threads a few days ago... so I am a little confused and I would appreciate some help! I isolated this code... and I wonder if I could use threads in it! #include <unistd.h> #endif #include <math.h> //#include "main.h" #include <sys/time.h>... (1 Reply)
Discussion started by: smurf2
1 Replies

10. UNIX for Advanced & Expert Users

scandir help

Hi everyone; I am trying to compile and execute a test program I wrote that calls scandir and it seems to not like my prototype. The Documentation on SUN for this function is clear, but I am missed something..... and I can't figure it out; I am using cc -gv -osaveas saveas.c on Sun... (1 Reply)
Discussion started by: dhelie
1 Replies
SCANDIR(3)						   BSD Library Functions Manual 						SCANDIR(3)

NAME
scandir, alphasort -- scan a directory LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <dirent.h> int scandir(const char *dirname, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); int scandir_b(const char *dirname, struct dirent ***namelist, int (*select(rp(const struct dirent *), int (^compar)(const struct dirent **, const struct dirent **)); int alphasort(const struct dirent **d1, const struct dirent **d2); DESCRIPTION
The scandir() function reads the directory dirname and builds an array of pointers to directory entries using malloc(3). It returns the num- ber of entries in the array. A pointer to the array of directory entries is stored in the location referenced by namelist. The select argument is a pointer to a user supplied subroutine which is called by scandir() to select which entries are to be included in the array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be included in the array. If select is null, then all the directory entries will be included. The compar argument is a pointer to a user supplied subroutine which is passed to qsort(3) to sort the completed array. If this pointer is null, the array is not sorted. The alphasort() function is a routine which can be used for the compar argument to sort the array alphabetically using strcoll(3). The memory allocated for the array can be deallocated with free(3), by freeing each pointer in the array and then the array itself. The scandir_b() function behaves in the same way as scandir(), but takes blocks as arguments instead of function pointers and calls qsort_b() rather than qsort(). DIAGNOSTICS
Returns -1 if the directory cannot be opened for reading or if malloc(3) cannot allocate enough memory to hold all the data structures. SEE ALSO
directory(3), malloc(3), qsort(3), strcoll(3), dir(5) HISTORY
The scandir() and alphasort() functions appeared in 4.2BSD. BSD
January 3, 2010 BSD
All times are GMT -4. The time now is 03:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy