delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/03/14/09:31:00

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <3AAF7F68.60785E60@salomon.at>
Date: Wed, 14 Mar 2001 15:25:44 +0100
From: Michael Haubenwallner <michael DOT haubenwallner AT salomon DOT at>
X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.18 i686)
X-Accept-Language: de-AT, en
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: 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 AT salomon DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019