mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
Added support for the "d_type" member of the "dirent" structure.
If the '_DIRENT_HAVE_D_TYPE' macro is defined after "#include <dirent.h>" 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.
This commit is contained in:
@ -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 <obarthel (at) gmx.net>
|
||||
* Copyright (c) 2002-2025 by Olaf Barthel <obarthel (at) gmx.net>
|
||||
* 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
|
||||
|
||||
@ -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 <obarthel (at) gmx.net>
|
||||
* Copyright (c) 2002-2025 by Olaf Barthel <obarthel (at) gmx.net>
|
||||
* 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);
|
||||
|
||||
Reference in New Issue
Block a user