This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: Re: A question about fileio, passing an empty string argument to chdir's problem
- From: eCos at sunnorth dot com dot cn
- To: ecos-discuss at ecos dot sourceware dot org
- Date: Fri, 29 Feb 2008 17:08:41 +0800
- Subject: Re: Re: [ECOS] A question about fileio, passing an empty string argument to chdir's problem
Dears;
Really sorry for my redundant emails. We thought we only sent the email 1
time, however, that is not the case. We had received email sending failure
not for 2 times, so we sent again, maybe that caused the problem, sorry
again
But I still have a question, I have tested on linux, CentOS5, gcc version
4.1.1 20070105 (Red Hat 4.1.1-52), calling open("", ...) will also return
ENOENT(Please see code below). So I write this mail to affirm it, could
you please look over this? Thanks so much.
SOURCE CODE
----------------------------------------------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
int
main(void)
{
int fd;
fd = open("", O_RDWR | O_CREAT);
printf("fd:%d\n", fd);
if(fd < 0)
printf("open error, errno:%d\n", errno);
else
close(fd);
return 0;
}
----------------------------------------------------------------
OUTPUT
----------------------------------------------------------------
fd:-1
open error, errno:2
----------------------------------------------------------------
***********************************************
Beijing Sunnorth eCos Maintainer Group
Maintainers:
liqin@sunnorth.com.cn
wanghui@sunnorth.com.cn
taiyun@sunnorth.com.cn
yxinghua@sunnorth.com.cn
Bejing Sunnorth Electronic Technology Co.,LTD
***********************************************
Andrew Lunn <andrew@lunn.ch>
发件人: ecos-discuss-owner@ecos.sourceware.org
2008-02-27 21:39
收件人
eCos@sunnorth.com.cn
抄送
ecos-discuss@ecos.sourceware.org
主题
Re: [ECOS] A question about fileio, passing an empty string argument
to chdir's problem
On Wed, Feb 27, 2008 at 06:06:43PM +0800, eCos@sunnorth.com.cn wrote:
> Dear all:
>
> We think there is a problem with eCos' chdir. When this fileio's
function
> is passed an empty
>
> string as its argument, eCos' chdir does nothing and will not fail.
> Calling chdir("") seems to
>
> have the same effect as chdir(".").
>
> However, as far as POSIX standard is concerned, calling chdir("") should
> fail and return ENOENT,
>
> just as described below(from POSIX document), please NOTE the contents
in
> the stars:
>
>
------------------------------------------------------------------------------------------------
> The chdir() function shall fail if:
> [EACCES]
> Search permission is denied for any component of the pathname.
> [ELOOP]
> A loop exists in symbolic links encountered during resolution of the
path
> argument.
> [ENAMETOOLONG]
> The length of the path argument exceeds {PATH_MAX} or a pathname
component
> is longer than
>
> {NAME_MAX}.
>
***********************************************************************************************
> [ENOENT]
> A component of path does not name an existing directory or path is an
> empty string.
>
***********************************************************************************************
> [ENOTDIR]
> A component of the pathname is not a directory.
>
------------------------------------------------------------------------------------------------
>
> We assume that eCos is in accord with POSIX as a matter of course, and
we
> think maybe this
>
> problem can be resolved by adding a check condition to cyg_mtab_lookup
> function, cause chdir
>
> (open, mkdir, etc. are the same) will call cyg_mtab_lookup()
I just checked the man pages for open and mkdir. Only chdir returns
ENOENT for a "" path. Also cyg_mtab_lookup() just finds the mount
point of a filesystem which contains the given path. To me i don't see
why it should be making checks which only apply to chdir().
I would put the check in chdir() itself.
Please send me a patch for this and also extend some of the test cases
which use chdir to test for chdir("") returns ENOENT.
As a side note. You are probably aware of this already, but remember
eCos is thread based, not process based. If a thread uses chdir() it
affects all threads. If you are porting Unix code which was originally
designed to run in a process, not a thread, you might get into
trouble.
Andrew
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss