From 8378274572f63274be49129bb4926ca863c943ed Mon Sep 17 00:00:00 2001 From: obarthel Date: Sat, 12 Jul 2025 12:17:12 +0200 Subject: [PATCH] Added support for the "d_type" member of the "dirent" structure. If the '_DIRENT_HAVE_D_TYPE' macro is defined after "#include " has been used successfully, it means that the "dirent" structure features the "d_type" member. The directory entry type values were adapted from 4.4BSD-Lite2, but not all of these are used. --- library/dirent_readdir.c | 36 +++++++++++++++++++++++++----------- library/include/dirent.h | 26 +++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/library/dirent_readdir.c b/library/dirent_readdir.c index d864a5b..0942e4d 100644 --- a/library/dirent_readdir.c +++ b/library/dirent_readdir.c @@ -1,10 +1,8 @@ /* - * $Id: dirent_readdir.c,v 1.10 2006-09-25 14:51:15 obarthel Exp $ - * * :ts=4 * * Portable ISO 'C' (1994) runtime library for the Amiga computer - * Copyright (c) 2002-2015 by Olaf Barthel + * Copyright (c) 2002-2025 by Olaf Barthel * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -79,9 +77,11 @@ readdir(DIR * directory_pointer) dh->dh_Position++; - dh->dh_DirectoryEntry.d_ino = 0; strcpy(dh->dh_DirectoryEntry.d_name,"."); + dh->dh_DirectoryEntry.d_ino = 0; + dh->dh_DirectoryEntry.d_type = DT_DIR; + result = &dh->dh_DirectoryEntry; } else @@ -115,8 +115,9 @@ readdir(DIR * directory_pointer) assert( sizeof(dh->dh_DirectoryEntry.d_name) >= sizeof(fib->fib_FileName) ); strcpy(dh->dh_DirectoryEntry.d_name,fib->fib_FileName); - + dh->dh_DirectoryEntry.d_ino = fib->fib_DiskKey; + dh->dh_DirectoryEntry.d_type = DT_DIR; result = &dh->dh_DirectoryEntry; } @@ -147,10 +148,11 @@ readdir(DIR * directory_pointer) dh->dh_Position++; - dh->dh_DirectoryEntry.d_ino = dh->dh_FileInfo.fib_DiskKey; - strcpy(dh->dh_DirectoryEntry.d_name,"."); + dh->dh_DirectoryEntry.d_ino = dh->dh_FileInfo.fib_DiskKey; + dh->dh_DirectoryEntry.d_type = DT_DIR; + result = &dh->dh_DirectoryEntry; } else if (dh->dh_Position == 1) @@ -176,10 +178,11 @@ readdir(DIR * directory_pointer) SHOWMSG("returning .."); - dh->dh_DirectoryEntry.d_ino = fib->fib_DiskKey; - strcpy(dh->dh_DirectoryEntry.d_name,".."); + dh->dh_DirectoryEntry.d_ino = fib->fib_DiskKey; + dh->dh_DirectoryEntry.d_type = DT_DIR; + result = &dh->dh_DirectoryEntry; } } @@ -192,12 +195,23 @@ readdir(DIR * directory_pointer) if(ExNext(dh->dh_DirLock,&dh->dh_FileInfo)) { - dh->dh_DirectoryEntry.d_ino = dh->dh_FileInfo.fib_DiskKey; - + int type; + assert( sizeof(dh->dh_DirectoryEntry.d_name) >= sizeof(dh->dh_FileInfo.fib_FileName) ); strcpy(dh->dh_DirectoryEntry.d_name,dh->dh_FileInfo.fib_FileName); + dh->dh_DirectoryEntry.d_ino = dh->dh_FileInfo.fib_DiskKey; + + if (dh->dh_FileInfo.fib_DirEntryType == ST_SOFTLINK) + type = DT_LNK; + else if (dh->dh_FileInfo.fib_DirEntryType < 0) + type = DT_REG; + else + type = DT_DIR; + + dh->dh_DirectoryEntry.d_type = type; + result = &dh->dh_DirectoryEntry; } else diff --git a/library/include/dirent.h b/library/include/dirent.h index e39faa2..6266266 100644 --- a/library/include/dirent.h +++ b/library/include/dirent.h @@ -1,10 +1,8 @@ /* - * $Id: dirent.h,v 1.7 2006-01-08 12:06:14 obarthel Exp $ - * * :ts=4 * * Portable ISO 'C' (1994) runtime library for the Amiga computer - * Copyright (c) 2002-2015 by Olaf Barthel + * Copyright (c) 2002-2025 by Olaf Barthel * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -75,8 +73,30 @@ struct dirent { ino_t d_ino; char d_name[NAME_MAX+1]; + int d_type; }; +#define _DIRENT_HAVE_D_TYPE + +/****************************************************************************/ + +/* Note that the directory entry type is not a POSIX feature, but it will + * make life easier for porting code which expects the 'd_type' structure + * member in the 'struct dirent'. + * + * The following types are not all supported on the Amiga. For the time being, + * DT_DIR (directory), DT_REG (regular file) and DT_LNK (soft link) should make + * sense. + */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 + /****************************************************************************/ extern DIR * opendir(const char * path_name);