This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

1.1.8: stat() (ntsec) clears reentrant-buffer for strtok()


Hi there!

This is my problem with stat() and strtok() on 1.1.8:

stat() seems to clear the reentrant-buffer for strtok()
if ntsec is set in the CYGWIN environment-variable.

So i found _REENT->_new._reent._strtok_last in the
strtok-source, and my test-program included here uses
this to see what happens (hope you can reproduce).

Yes, i know it may be better to use strtok_r(), but my
program already works on HP-UX, AIX, Linux, SunOS and
Win32 using MSVC 5.0 too.

I noticed this strange behaviour both on WinNT 4.0 and Win2K,
everywhere using only NTFS as the local filesystem, using
$ `gcc -v`
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-6/specs
gcc version 2.95.2-6 19991024 (cygwin experimental)

You may try my test-program with and without ntsec
set in your CYGWIN-var to see what i mean.

Thank you for the great thing making a
complete Unix-environment possible on Windows!

-- haubi

Michael Haubenwallner                        F&E
S a l o m o n        Automationstechnik     GmbH
Friesachstr. 15,  8114 Friesach b. Graz, Austria
Phone: (++43) 3127 200-308           Fax: 200-22
mailto:haubi@salomon.at    http://www.salomon.at



8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
    char        origpath[]="/check/this/path/for/existance";
    char        path[1024] = "/";
    struct stat statbuf;
    int         rv;
    char        *ptr;

    ptr = strtok(origpath, "/");

    while(ptr != NULL) {
        strcat(path, ptr);

        printf("_REENT->_new._reent._strtok_last is %p (%s)\n",
            _REENT->_new._reent._strtok_last,
            (_REENT->_new._reent._strtok_last)
            ? _REENT->_new._reent._strtok_last : "<nil>");

        rv = stat(path, &statbuf);

        printf("_REENT->_new._reent._strtok_last is %p (%s)\n",
            _REENT->_new._reent._strtok_last,
            (_REENT->_new._reent._strtok_last)
            ? _REENT->_new._reent._strtok_last : "<nil>");

        if (rv < 0) {
            rv = mkdir(path, 0777);
            if (rv < 0) {
                fprintf(stderr, "can't create '%s': %s\n",
                    path, strerror(errno));
                break;
            } else {
                printf("created: '%s'\n", path);
            }
        } else {
            printf("exists: '%s'\n", path);
        }

        strcat(path, "/");

        ptr = strtok(NULL, "/");
    }

    return rv;
}

>8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]