From: sandmann AT clio DOT rice DOT edu (Charles Sandmann) Message-Id: <10109251334.AA16870@clio.rice.edu> Subject: chdir patch (resend 2) To: djgpp-workers AT delorie DOT com Date: Tue, 25 Sep 2001 08:34:52 -0500 (CDT) X-Mailer: ELM [version 2.5 PL2] Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com My messages to djgpp-workers seem to disappear into a black hole if they have an "name" after them (so items sent to my alias didn't appear...) This seems to prevent the chdir problems in my quick testing (on Win2K only). In a nutshell, if after the chdir, getcwd indicates root directory, and we didn't set a root directory, fail and put us back. May want to save the original getcwd return status and only _chdir back if OK. May also want to _chdir back on regular error. Comments? Very busy week so I need some help building an rm and to make sure this or an improvement eliminates the problem. Thanks. (p.s. committed many changes associated with _os_trueversion). *** chdir.c_ Tue Aug 22 12:41:16 2000 --- chdir.c Mon Sep 24 21:38:52 2001 *************** __chdir (const char *mydirname) *** 23,26 **** --- 23,29 ---- char real_name[FILENAME_MAX]; char path[FILENAME_MAX]; + char olddir[FILENAME_MAX], newdir[FILENAME_MAX], *rv; + + __getcwd(olddir, sizeof(olddir)); /* Failure OK if set OK */ if (!__solve_symlinks(mydirname, real_name)) *************** __chdir (const char *mydirname) *** 73,76 **** --- 76,88 ---- } + /* Check for path too long issues on Windows 2000 or W9x with lfn=n */ + rv = __getcwd(newdir, sizeof(newdir)); + if(!rv || (rv[3] == 0 && path[3] != 0) ) { + /* get failed, or returned root dir and path set was not root */ + __chdir(olddir); + errno = ENOENT; + return -1; + } + return 0; }