Re: Possible problem with readdir() and/or lstat()
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Hz3U8cQdZ8SM8RlTNUaSGLVo8ZjmQnQ/HDz5pQdAG2WVha68S0pbV/d8a6zWCxyuDdflh9EcJT/nn4zTwcPcAq3mTtBkLWF/UI2aeeA9n/+bGDzalE7Dwwp2bXVtoksDU85UACumuNrzfrAaOP45uBs3hwIionj1flXWTTTd5Es= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=coABXYTIeU9iPzMzAJTQhvOx9/fAmb1bueCETw6bTi1vBTOYDGU2YHInutG8poFVjBwpSnLrw+yOOv8NqGRkjtK/dP2jtm2aejO6b8mOPil2CUiMZazdInz/3XfYFjcYkJnwzOJvp+avFk5rZQ5EgrH2w5YmGGizcMTDpUGIs8c= entry->d_name is relative to dir so the lstat() call is failing. You are displaying the result from the lstat("..") call. -john [Apologies for the double-post; I just realized darwin-userlevel was the wrong group for this.] % cat test.c #include <sys/stat.h> #include <dirent.h> #include <stdio.h> #include <assert.h> int main( int argc, char** argv ) { DIR* dir ; struct dirent* entry ; struct stat buf ; assert(argc == 2) ; dir = opendir(argv[1]) ; assert(dir != 0) ; while( (entry = readdir(dir)) != 0 ) { lstat(entry->d_name, &buf) ; printf("name: %s --- S_ISDIR: %d\n", entry->d_name, S_ISDIR(buf.st_mode)) ; } return 0 ; } % gcc test.c -o test % file * file1: ASCII text file2: ASCII text somedir: directory test: Mach-O executable i386 test.c: ASCII C program text % ./test . name: . --- S_ISDIR: 1 name: .. --- S_ISDIR: 1 name: file1 --- S_ISDIR: 0 name: file2 --- S_ISDIR: 0 name: somedir --- S_ISDIR: 1 name: test --- S_ISDIR: 0 name: test.c --- S_ISDIR: 0 % file somedir/* somedir/file3: ASCII text somedir/file4: ASCII text somedir/somedir2: directory % ./test somedir name: . --- S_ISDIR: 1 name: .. --- S_ISDIR: 1 name: file3 --- S_ISDIR: 1 name: file4 --- S_ISDIR: 1 name: somedir2 --- S_ISDIR: 1 Note that file3 and file4 are not directories. ____________________________________________________________________________________ TV dinner still cooling? Check out "Tonight's Picks" on Yahoo! TV. http://tv.yahoo.com/ _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/jahayes%40gmail.com This email sent to jahayes@gmail.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On 3/30/07, Jeff Sparks <jeffrsparks@yahoo.com> wrote: This email sent to site_archiver@lists.apple.com
participants (1)
-
John Hayes