Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: null bytes in file names?



On Mon, Apr 07, 2003 at 10:32:21AM +0200, Dominik Vogt wrote:
> As far as I know, UNIX file systems allow null bytes in file
> names.  Out of curiosity I tried generating such a file.  I edited
> a file fn in a hex editor and put a single null byte into it.

Your knowledge is somewhat faulty.
There are exactly two characters that Unix does not allow in filenames.
Those are NUL (ASCII code 0) and / (ASCII code 47).
The former is used to indicate the end of a filename, while the latter
is used to separate directory paths.

So, you cant't have null bytes in a filename under Unix.

> 
> Take I (with "touch"):
> 
>   $ touch $(< fn)
>   touch: creating `': No such file or directory
>   touch: creating `': No such file or directory
>   $ touch $(< fn)
>   touch: creating `': No such file or directory
>   $ touch s$(< fn)t
>   $ touch u"$(< fn)"v
>   $ ls
>   fn s t u
> 
> "u" might actually be named "u^@v" but displayed incorrectly by ls,
> so let's try to access a file named "u".
> 
>   $ ls u
>   u
> 
> Nope, the name got cut off.
> 
>   $ rm s t y
> 
> Take II (shell builtins only):
> 
>   $ echo foo > $(< fn)
>   zsh: no such file or directory: 
>   $ echo foo > "$(< fn)"
>   zsh: no such file or directory: ^@
>   $ echo foo > w$(< fn)x
>   $ echo foo > y$(< fn)z
>   $ ls
>   fn w  x  y  z
>   $ ls w y
>   w  y
> 
> So, no luck.  I wonder where the problem comes from:
> 
>  - zsh? (4.0.4)
>  - libc?
>  - kernel? (linux-2.4.20)
> 
> Bye
> 
> Dominik ^_^  ^_^

-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@xxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author