Emulate ENOTDIR better

This commit is contained in:
Justine Tunney 2023-08-16 20:11:19 -07:00
parent b76b2be2d0
commit 8d1c81ac9f
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
35 changed files with 80 additions and 50 deletions

View file

@ -47,6 +47,9 @@ TEST(open, enoent) {
TEST(open, enotdir) {
ASSERT_SYS(0, 0, touch("o", 0644));
ASSERT_SYS(ENOTDIR, -1, open("o/", O_RDONLY));
ASSERT_SYS(ENOTDIR, -1, open("o/.", O_RDONLY));
ASSERT_SYS(ENOTDIR, -1, open("o/./", O_RDONLY));
ASSERT_SYS(ENOTDIR, -1, open("o/doesnotexist", O_RDONLY));
}

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/mem/gc.h"
@ -82,3 +83,12 @@ TEST(zipos_O_DIRECTORY, blocksOpeningOfNormalFiles) {
ASSERT_SYS(ENOTDIR, -1,
open("/zip/libc/testlib/hyperion.txt", O_RDONLY | O_DIRECTORY));
}
TEST(zipos, trailingComponents_willEnodirFile) {
struct stat st;
ASSERT_SYS(ENOTDIR, -1, open("/zip/libc/testlib/hyperion.txt/", O_RDONLY));
ASSERT_SYS(ENOTDIR, -1, open("/zip/libc/testlib/hyperion.txt/.", O_RDONLY));
ASSERT_SYS(ENOTDIR, -1, open("/zip/libc/testlib/hyperion.txt/./", O_RDONLY));
ASSERT_SYS(ENOTDIR, -1, open("/zip/libc/testlib/hyperion.txt/a/b", O_RDONLY));
ASSERT_SYS(ENOTDIR, -1, stat("/zip/libc/testlib/hyperion.txt/", &st));
}

View file

@ -93,9 +93,10 @@ TEST(__zipos_normpath, vectors) {
{"./", ""},
{"..", ""},
{"../", ""},
{"foo/", "foo/"},
{"../abc/def", "abc/def"},
{"../abc/def/..", "abc"},
{"../abc/././././def/..", "abc"},
{"../abc/def/..", "abc/"},
{"../abc/././././def/..", "abc/"},
{"////../abc/def", "abc/def"},
{"/../def", "def"},
{"../def", "def"},
@ -121,11 +122,11 @@ TEST(__zipos_normpath, vectors) {
{"../../../a", "a"},
{"../a../../a", "a"},
{"cccc/abc////..////.//../", ""},
{"aaaa/cccc/abc////..////.//../", "aaaa"},
{"..//////.///..////..////.//////abc////.////..////def//abc/..", "def"},
{"aaaa/cccc/abc////..////.//../", "aaaa/"},
{"..//////.///..////..////.//////abc////.////..////def//abc/..", "def/"},
{"////////////..//////.///..////..////.//////abc////.////..////def//abc/"
"..",
"def"},
"def/"},
};
int fails = 0;