- ANSI C
- » Variable handling
- » Miscellaneous
- » POSIX
- » Date/Time
- » Math
- » menu_code_ansiccode_strings
- » PCRE
- » Arrays
- » Classes
- » Program execute
- » Directories
- » Filesystem
- » Memory
- » GD
- » Network
- » Sockets
- PERL
- PHP
- JavaScript
CONTENT
- CHANGES
Szukaj
#top Directories¶
- Directories
- Makefile
- Makefile (linux)
- Makefile.obsd
- Makefile.fbsd
- Makefile.sol
- Makefile.beos
- Makefile.win
- Predefined Constants
- DT_***
- GLOB_***
- Datatypes / MACROS
- __blkcnt_t
- __blksize_t
- __dev_t
- __gid_t
- __ino_t
- __mode_t
- __nlink_t
- __off_t
- __size_t
- __ssize_t
- __time_t
- __uid_t
- DIR
- glob_t
- off_t
- size_t
- struct dirent
- struct linux_dirent
- struct stat
- struct timespec
- Directory Functions
- alphasort
- chdir
- chroot
- closedir
- dirfd
- fdopendir
- getcwd
- getdents
- getdirentries
- glob
- globfree
- mkdir
- mkdirat
- opendir
- readdir
- rewinddir
- rmdir
- scandir
- seekdir
- telldir
- versionsort
code / ansic / sysdir
#top Makefile¶
Dla ułatwienia korzystania z przykładów został utworzony jeden zbiorczy plik
Makefile
kompilujący przykłady użycia poniżej wymienionych funkcji związanych z operacjami na systemie plików (funkcje dotyczące operacji na katalogach).Poniższe pliki Makefile zakładają obecność wszystkich plików przykładów, w przypadku chęci kompilacji za pomocą Makefile tylko wybranego przykładu należy zakomentować w pliku Makefile ostatnią pozycję zawierającą listę wszystkich targetów do wykonania
make: $(ALPHASORT) ...
, a następnie odkomentować powyżej komendę make zawierającą nazwę targetu dla bieżącego przykładu, np: w przypadku chęci kompilacji tylko przykładu chdir
należy zakomentować ostatnią pozycję rozpoczynającą się od make: $(ALPHASORT) ...
(wstawić na początku przed make znak #
), a następnie odkomentować pozycję: #make: $(ALPHASORT)
(usunąć znak #
).#top Makefile (linux)¶
SELECT ALL
# Project: Project # Makefile created GCC = gcc INCS = -DHAVE_DIRENT_TYPEOFF=1 -DHAVE_FDOPENDIR=1 -DHAVE_FNMATCH=1 -DHAVE_GETDIRENTRIES=1 -DHAVE_GLOB=1 -DHAVE_MKDIR_MODE=1 -DHAVE_SCANDIR=1 -DHAVE_VERSIONSORT=1 CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long -Wformat-security -D_FILE_OFFSET_BITS=64 -D_LINUX -D_REENTRANT CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long LIBS = LIBDIRS = LDFLAGS = $(LIBDIRS) $(LIBS) RM = rm -f MKDCMD = mkdir -p ALPHASORT = alphasort CHDIR = chdir CHROOT = chroot CLOSEDIR = closedir DIRFD = dirfd FDOPENDIR = fdopendir GETCWD = getcwd GETDIRENTRIES= getdirentries GLOB = glob GLOB_FNMATCH= glob-fnmatch GLOBFREE = globfree MKDIR = mkdir OPENDIR = opendir READDIR = readdir REWINDDIR = rewinddir RMDIR = rmdir SCANDIR = scandir SEEKDIR = seekdir TELLDIR = telldir VERSIONSORT = versionsort all: objdir make objdir: $(MKDCMD) obj/ clean: objdir $(RM) obj/*.o *.o *~ #make: $(ALPHASORT) #make: $(CHDIR) #make: $(CHROOT) #make: $(CLOSEDIR) #make: $(DIRFD) #make: $(FDOPENDIR) #make: $(GETCWD) #make: $(GETDIRENTRIES) #make: $(GLOB) #make: $(GLOB_FNMATCH) #make: $(GLOBFREE) #make: $(MKDIR) #make: $(OPENDIR) #make: $(READDIR) #make: $(REWINDDIR) #make: $(RMDIR) #make: $(SCANDIR) #make: $(SEEKDIR) #make: $(TELLDIR) #make: $(VERSIONSORT) make: $(ALPHASORT) $(CHDIR) $(CHROOT) $(CLOSEDIR) $(DIRFD) $(FDOPENDIR) $(GETCWD) $(GETDIRENTRIES) $(GLOB) $(GLOB_FNMATCH) $(GLOBFREE) $(MKDIR) $(OPENDIR) $(READDIR) $(REWINDDIR) $(RMDIR) $(SCANDIR) $(SEEKDIR) $(TELLDIR) $(VERSIONSORT) $(ALPHASORT): $(ALPHASORT).o $(GCC) -o $(ALPHASORT) obj/$(ALPHASORT).o $(LDFLAGS) $(ALPHASORT).o: $(GCC) -o obj/$(ALPHASORT).o -c $(ALPHASORT).c $(CFLAGS) $(CHDIR): $(CHDIR).o $(GCC) -o $(CHDIR) obj/$(CHDIR).o $(LDFLAGS) $(CHDIR).o: $(GCC) -o obj/$(CHDIR).o -c $(CHDIR).c $(CFLAGS) $(CHROOT): $(CHROOT).o $(GCC) -o $(CHROOT) obj/$(CHROOT).o $(LDFLAGS) $(CHROOT).o: $(GCC) -o obj/$(CHROOT).o -c $(CHROOT).c $(CFLAGS) $(CLOSEDIR): $(CLOSEDIR).o $(GCC) -o $(CLOSEDIR) obj/$(CLOSEDIR).o $(LDFLAGS) $(CLOSEDIR).o: $(GCC) -o obj/$(CLOSEDIR).o -c $(CLOSEDIR).c $(CFLAGS) $(DIRFD): $(DIRFD).o $(GCC) -o $(DIRFD) obj/$(DIRFD).o $(LDFLAGS) $(DIRFD).o: $(GCC) -o obj/$(DIRFD).o -c $(DIRFD).c $(CFLAGS) $(FDOPENDIR): $(FDOPENDIR).o $(GCC) -o $(FDOPENDIR) obj/$(FDOPENDIR).o $(LDFLAGS) $(FDOPENDIR).o: $(GCC) -o obj/$(FDOPENDIR).o -c $(FDOPENDIR).c $(CFLAGS) $(GETCWD): $(GETCWD).o $(GCC) -o $(GETCWD) obj/$(GETCWD).o $(LDFLAGS) $(GETCWD).o: $(GCC) -o obj/$(GETCWD).o -c $(GETCWD).c $(CFLAGS) $(GETDIRENTRIES): $(GETDIRENTRIES).o $(GCC) -o $(GETDIRENTRIES) obj/$(GETDIRENTRIES).o $(LDFLAGS) $(GETDIRENTRIES).o: $(GCC) -o obj/$(GETDIRENTRIES).o -c $(GETDIRENTRIES).c $(CFLAGS) $(GLOB): $(GLOB).o $(GCC) -o $(GLOB) obj/$(GLOB).o $(LDFLAGS) $(GLOB).o: $(GCC) -o obj/$(GLOB).o -c $(GLOB).c $(CFLAGS) $(GLOB_FNMATCH): $(GLOB_FNMATCH).o $(GCC) -o $(GLOB_FNMATCH) obj/$(GLOB_FNMATCH).o $(LDFLAGS) $(GLOB_FNMATCH).o: $(GCC) -o obj/$(GLOB_FNMATCH).o -c $(GLOB_FNMATCH).c $(CFLAGS) $(GLOBFREE): $(GLOBFREE).o $(GCC) -o $(GLOBFREE) obj/$(GLOBFREE).o $(LDFLAGS) $(GLOBFREE).o: $(GCC) -o obj/$(GLOBFREE).o -c $(GLOBFREE).c $(CFLAGS) $(MKDIR): $(MKDIR).o $(GCC) -o $(MKDIR) obj/$(MKDIR).o $(LDFLAGS) $(MKDIR).o: $(GCC) -o obj/$(MKDIR).o -c $(MKDIR).c $(CFLAGS) $(OPENDIR): $(OPENDIR).o $(GCC) -o $(OPENDIR) obj/$(OPENDIR).o $(LDFLAGS) $(OPENDIR).o: $(GCC) -o obj/$(OPENDIR).o -c $(OPENDIR).c $(CFLAGS) $(READDIR): $(READDIR).o $(GCC) -o $(READDIR) obj/$(READDIR).o $(LDFLAGS) $(READDIR).o: $(GCC) -o obj/$(READDIR).o -c $(READDIR).c $(CFLAGS) $(REWINDDIR): $(REWINDDIR).o $(GCC) -o $(REWINDDIR) obj/$(REWINDDIR).o $(LDFLAGS) $(REWINDDIR).o: $(GCC) -o obj/$(REWINDDIR).o -c $(REWINDDIR).c $(CFLAGS) $(RMDIR): $(RMDIR).o $(GCC) -o $(RMDIR) obj/$(RMDIR).o $(LDFLAGS) $(RMDIR).o: $(GCC) -o obj/$(RMDIR).o -c $(RMDIR).c $(CFLAGS) $(SCANDIR): $(SCANDIR).o $(GCC) -o $(SCANDIR) obj/$(SCANDIR).o $(LDFLAGS) $(SCANDIR).o: $(GCC) -o obj/$(SCANDIR).o -c $(SCANDIR).c $(CFLAGS) $(SEEKDIR): $(SEEKDIR).o $(GCC) -o $(SEEKDIR) obj/$(SEEKDIR).o $(LDFLAGS) $(SEEKDIR).o: $(GCC) -o obj/$(SEEKDIR).o -c $(SEEKDIR).c $(CFLAGS) $(TELLDIR): $(TELLDIR).o $(GCC) -o $(TELLDIR) obj/$(TELLDIR).o $(LDFLAGS) $(TELLDIR).o: $(GCC) -o obj/$(TELLDIR).o -c $(TELLDIR).c $(CFLAGS) $(VERSIONSORT): $(VERSIONSORT).o $(GCC) -o $(VERSIONSORT) obj/$(VERSIONSORT).o $(LDFLAGS) $(VERSIONSORT).o: $(GCC) -o obj/$(VERSIONSORT).o -c $(VERSIONSORT).c $(CFLAGS)
#top Makefile.obsd¶
SELECT ALL
# Project: Project # Makefile created GCC = gcc INCS = -DHAVE_FNMATCH=1 -DHAVE_GETDIRENTRIES=1 -DHAVE_GLOB=1 -DHAVE_MKDIR_MODE=1 -DHAVE_SCANDIR=1 CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long -D_FILE_OFFSET_BITS=64 -D_LINUX -D_REENTRANT CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long LIBS = LIBDIRS = LDFLAGS = $(LIBDIRS) $(LIBS) RM = rm -f MKDCMD = mkdir -p ALPHASORT = alphasort CHDIR = chdir CHROOT = chroot CLOSEDIR = closedir DIRFD = dirfd FDOPENDIR = fdopendir GETCWD = getcwd GETDIRENTRIES= getdirentries GLOB = glob GLOB_FNMATCH= glob-fnmatch GLOBFREE = globfree MKDIR = mkdir OPENDIR = opendir READDIR = readdir REWINDDIR = rewinddir RMDIR = rmdir SCANDIR = scandir SEEKDIR = seekdir TELLDIR = telldir VERSIONSORT = versionsort all: objdir make objdir: $(MKDCMD) obj/ clean: objdir $(RM) obj/*.o *.o *~ #make: $(ALPHASORT) #make: $(CHDIR) #make: $(CHROOT) #make: $(CLOSEDIR) #make: $(DIRFD) #make: $(FDOPENDIR) #make: $(GETCWD) #make: $(GETDIRENTRIES) #make: $(GLOB) #make: $(GLOB_FNMATCH) #make: $(GLOBFREE) #make: $(MKDIR) #make: $(OPENDIR) #make: $(READDIR) #make: $(REWINDDIR) #make: $(RMDIR) #make: $(SCANDIR) #make: $(SEEKDIR) #make: $(TELLDIR) #make: $(VERSIONSORT) make: $(ALPHASORT) $(CHDIR) $(CHROOT) $(CLOSEDIR) $(DIRFD) $(FDOPENDIR) $(GETCWD) $(GETDIRENTRIES) $(GLOB) $(GLOB_FNMATCH) $(GLOBFREE) $(MKDIR) $(OPENDIR) $(READDIR) $(REWINDDIR) $(RMDIR) $(SCANDIR) $(SEEKDIR) $(TELLDIR) $(VERSIONSORT) $(ALPHASORT): $(ALPHASORT).o $(GCC) -o $(ALPHASORT) obj/$(ALPHASORT).o $(LDFLAGS) $(ALPHASORT).o: $(GCC) -o obj/$(ALPHASORT).o -c $(ALPHASORT).c $(CFLAGS) $(CHDIR): $(CHDIR).o $(GCC) -o $(CHDIR) obj/$(CHDIR).o $(LDFLAGS) $(CHDIR).o: $(GCC) -o obj/$(CHDIR).o -c $(CHDIR).c $(CFLAGS) $(CHROOT): $(CHROOT).o $(GCC) -o $(CHROOT) obj/$(CHROOT).o $(LDFLAGS) $(CHROOT).o: $(GCC) -o obj/$(CHROOT).o -c $(CHROOT).c $(CFLAGS) $(CLOSEDIR): $(CLOSEDIR).o $(GCC) -o $(CLOSEDIR) obj/$(CLOSEDIR).o $(LDFLAGS) $(CLOSEDIR).o: $(GCC) -o obj/$(CLOSEDIR).o -c $(CLOSEDIR).c $(CFLAGS) $(DIRFD): $(DIRFD).o $(GCC) -o $(DIRFD) obj/$(DIRFD).o $(LDFLAGS) $(DIRFD).o: $(GCC) -o obj/$(DIRFD).o -c $(DIRFD).c $(CFLAGS) $(FDOPENDIR): $(FDOPENDIR).o $(GCC) -o $(FDOPENDIR) obj/$(FDOPENDIR).o $(LDFLAGS) $(FDOPENDIR).o: $(GCC) -o obj/$(FDOPENDIR).o -c $(FDOPENDIR).c $(CFLAGS) $(GETCWD): $(GETCWD).o $(GCC) -o $(GETCWD) obj/$(GETCWD).o $(LDFLAGS) $(GETCWD).o: $(GCC) -o obj/$(GETCWD).o -c $(GETCWD).c $(CFLAGS) $(GETDIRENTRIES): $(GETDIRENTRIES).o $(GCC) -o $(GETDIRENTRIES) obj/$(GETDIRENTRIES).o $(LDFLAGS) $(GETDIRENTRIES).o: $(GCC) -o obj/$(GETDIRENTRIES).o -c $(GETDIRENTRIES).c $(CFLAGS) $(GLOB): $(GLOB).o $(GCC) -o $(GLOB) obj/$(GLOB).o $(LDFLAGS) $(GLOB).o: $(GCC) -o obj/$(GLOB).o -c $(GLOB).c $(CFLAGS) $(GLOB_FNMATCH): $(GLOB_FNMATCH).o $(GCC) -o $(GLOB_FNMATCH) obj/$(GLOB_FNMATCH).o $(LDFLAGS) $(GLOB_FNMATCH).o: $(GCC) -o obj/$(GLOB_FNMATCH).o -c $(GLOB_FNMATCH).c $(CFLAGS) $(GLOBFREE): $(GLOBFREE).o $(GCC) -o $(GLOBFREE) obj/$(GLOBFREE).o $(LDFLAGS) $(GLOBFREE).o: $(GCC) -o obj/$(GLOBFREE).o -c $(GLOBFREE).c $(CFLAGS) $(MKDIR): $(MKDIR).o $(GCC) -o $(MKDIR) obj/$(MKDIR).o $(LDFLAGS) $(MKDIR).o: $(GCC) -o obj/$(MKDIR).o -c $(MKDIR).c $(CFLAGS) $(OPENDIR): $(OPENDIR).o $(GCC) -o $(OPENDIR) obj/$(OPENDIR).o $(LDFLAGS) $(OPENDIR).o: $(GCC) -o obj/$(OPENDIR).o -c $(OPENDIR).c $(CFLAGS) $(READDIR): $(READDIR).o $(GCC) -o $(READDIR) obj/$(READDIR).o $(LDFLAGS) $(READDIR).o: $(GCC) -o obj/$(READDIR).o -c $(READDIR).c $(CFLAGS) $(REWINDDIR): $(REWINDDIR).o $(GCC) -o $(REWINDDIR) obj/$(REWINDDIR).o $(LDFLAGS) $(REWINDDIR).o: $(GCC) -o obj/$(REWINDDIR).o -c $(REWINDDIR).c $(CFLAGS) $(RMDIR): $(RMDIR).o $(GCC) -o $(RMDIR) obj/$(RMDIR).o $(LDFLAGS) $(RMDIR).o: $(GCC) -o obj/$(RMDIR).o -c $(RMDIR).c $(CFLAGS) $(SCANDIR): $(SCANDIR).o $(GCC) -o $(SCANDIR) obj/$(SCANDIR).o $(LDFLAGS) $(SCANDIR).o: $(GCC) -o obj/$(SCANDIR).o -c $(SCANDIR).c $(CFLAGS) $(SEEKDIR): $(SEEKDIR).o $(GCC) -o $(SEEKDIR) obj/$(SEEKDIR).o $(LDFLAGS) $(SEEKDIR).o: $(GCC) -o obj/$(SEEKDIR).o -c $(SEEKDIR).c $(CFLAGS) $(TELLDIR): $(TELLDIR).o $(GCC) -o $(TELLDIR) obj/$(TELLDIR).o $(LDFLAGS) $(TELLDIR).o: $(GCC) -o obj/$(TELLDIR).o -c $(TELLDIR).c $(CFLAGS) $(VERSIONSORT): $(VERSIONSORT).o $(GCC) -o $(VERSIONSORT) obj/$(VERSIONSORT).o $(LDFLAGS) $(VERSIONSORT).o: $(GCC) -o obj/$(VERSIONSORT).o -c $(VERSIONSORT).c $(CFLAGS)
#top Makefile.fbsd¶
SELECT ALL
# Project: Project # Makefile created GCC = gcc INCS = -DHAVE_FDOPENDIR=1 -DHAVE_FNMATCH=1 -DHAVE_GETDIRENTRIES=1 -DHAVE_GLOB=1 -DHAVE_MKDIR_MODE=1 -DHAVE_SCANDIR=1 CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long -D_FILE_OFFSET_BITS=64 -D_LINUX -D_REENTRANT CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long LIBS = LIBDIRS = LDFLAGS = $(LIBDIRS) $(LIBS) RM = rm -f MKDCMD = mkdir -p ALPHASORT = alphasort CHDIR = chdir CHROOT = chroot CLOSEDIR = closedir DIRFD = dirfd FDOPENDIR = fdopendir GETCWD = getcwd GETDIRENTRIES= getdirentries GLOB = glob GLOB_FNMATCH= glob-fnmatch GLOBFREE = globfree MKDIR = mkdir OPENDIR = opendir READDIR = readdir REWINDDIR = rewinddir RMDIR = rmdir SCANDIR = scandir SEEKDIR = seekdir TELLDIR = telldir VERSIONSORT = versionsort all: objdir make objdir: $(MKDCMD) obj/ clean: objdir $(RM) obj/*.o *.o *~ #make: $(ALPHASORT) #make: $(CHDIR) #make: $(CHROOT) #make: $(CLOSEDIR) #make: $(DIRFD) #make: $(FDOPENDIR) #make: $(GETCWD) #make: $(GETDIRENTRIES) #make: $(GLOB) #make: $(GLOB_FNMATCH) #make: $(GLOBFREE) #make: $(MKDIR) #make: $(OPENDIR) #make: $(READDIR) #make: $(REWINDDIR) #make: $(RMDIR) #make: $(SCANDIR) #make: $(SEEKDIR) #make: $(TELLDIR) #make: $(VERSIONSORT) make: $(ALPHASORT) $(CHDIR) $(CHROOT) $(CLOSEDIR) $(DIRFD) $(FDOPENDIR) $(GETCWD) $(GETDIRENTRIES) $(GLOB) $(GLOB_FNMATCH) $(GLOBFREE) $(MKDIR) $(OPENDIR) $(READDIR) $(REWINDDIR) $(RMDIR) $(SCANDIR) $(SEEKDIR) $(TELLDIR) $(VERSIONSORT) $(ALPHASORT): $(ALPHASORT).o $(GCC) -o $(ALPHASORT) obj/$(ALPHASORT).o $(LDFLAGS) $(ALPHASORT).o: $(GCC) -o obj/$(ALPHASORT).o -c $(ALPHASORT).c $(CFLAGS) $(CHDIR): $(CHDIR).o $(GCC) -o $(CHDIR) obj/$(CHDIR).o $(LDFLAGS) $(CHDIR).o: $(GCC) -o obj/$(CHDIR).o -c $(CHDIR).c $(CFLAGS) $(CHROOT): $(CHROOT).o $(GCC) -o $(CHROOT) obj/$(CHROOT).o $(LDFLAGS) $(CHROOT).o: $(GCC) -o obj/$(CHROOT).o -c $(CHROOT).c $(CFLAGS) $(CLOSEDIR): $(CLOSEDIR).o $(GCC) -o $(CLOSEDIR) obj/$(CLOSEDIR).o $(LDFLAGS) $(CLOSEDIR).o: $(GCC) -o obj/$(CLOSEDIR).o -c $(CLOSEDIR).c $(CFLAGS) $(DIRFD): $(DIRFD).o $(GCC) -o $(DIRFD) obj/$(DIRFD).o $(LDFLAGS) $(DIRFD).o: $(GCC) -o obj/$(DIRFD).o -c $(DIRFD).c $(CFLAGS) $(FDOPENDIR): $(FDOPENDIR).o $(GCC) -o $(FDOPENDIR) obj/$(FDOPENDIR).o $(LDFLAGS) $(FDOPENDIR).o: $(GCC) -o obj/$(FDOPENDIR).o -c $(FDOPENDIR).c $(CFLAGS) $(GETCWD): $(GETCWD).o $(GCC) -o $(GETCWD) obj/$(GETCWD).o $(LDFLAGS) $(GETCWD).o: $(GCC) -o obj/$(GETCWD).o -c $(GETCWD).c $(CFLAGS) $(GETDIRENTRIES): $(GETDIRENTRIES).o $(GCC) -o $(GETDIRENTRIES) obj/$(GETDIRENTRIES).o $(LDFLAGS) $(GETDIRENTRIES).o: $(GCC) -o obj/$(GETDIRENTRIES).o -c $(GETDIRENTRIES).c $(CFLAGS) $(GLOB): $(GLOB).o $(GCC) -o $(GLOB) obj/$(GLOB).o $(LDFLAGS) $(GLOB).o: $(GCC) -o obj/$(GLOB).o -c $(GLOB).c $(CFLAGS) $(GLOB_FNMATCH): $(GLOB_FNMATCH).o $(GCC) -o $(GLOB_FNMATCH) obj/$(GLOB_FNMATCH).o $(LDFLAGS) $(GLOB_FNMATCH).o: $(GCC) -o obj/$(GLOB_FNMATCH).o -c $(GLOB_FNMATCH).c $(CFLAGS) $(GLOBFREE): $(GLOBFREE).o $(GCC) -o $(GLOBFREE) obj/$(GLOBFREE).o $(LDFLAGS) $(GLOBFREE).o: $(GCC) -o obj/$(GLOBFREE).o -c $(GLOBFREE).c $(CFLAGS) $(MKDIR): $(MKDIR).o $(GCC) -o $(MKDIR) obj/$(MKDIR).o $(LDFLAGS) $(MKDIR).o: $(GCC) -o obj/$(MKDIR).o -c $(MKDIR).c $(CFLAGS) $(OPENDIR): $(OPENDIR).o $(GCC) -o $(OPENDIR) obj/$(OPENDIR).o $(LDFLAGS) $(OPENDIR).o: $(GCC) -o obj/$(OPENDIR).o -c $(OPENDIR).c $(CFLAGS) $(READDIR): $(READDIR).o $(GCC) -o $(READDIR) obj/$(READDIR).o $(LDFLAGS) $(READDIR).o: $(GCC) -o obj/$(READDIR).o -c $(READDIR).c $(CFLAGS) $(REWINDDIR): $(REWINDDIR).o $(GCC) -o $(REWINDDIR) obj/$(REWINDDIR).o $(LDFLAGS) $(REWINDDIR).o: $(GCC) -o obj/$(REWINDDIR).o -c $(REWINDDIR).c $(CFLAGS) $(RMDIR): $(RMDIR).o $(GCC) -o $(RMDIR) obj/$(RMDIR).o $(LDFLAGS) $(RMDIR).o: $(GCC) -o obj/$(RMDIR).o -c $(RMDIR).c $(CFLAGS) $(SCANDIR): $(SCANDIR).o $(GCC) -o $(SCANDIR) obj/$(SCANDIR).o $(LDFLAGS) $(SCANDIR).o: $(GCC) -o obj/$(SCANDIR).o -c $(SCANDIR).c $(CFLAGS) $(SEEKDIR): $(SEEKDIR).o $(GCC) -o $(SEEKDIR) obj/$(SEEKDIR).o $(LDFLAGS) $(SEEKDIR).o: $(GCC) -o obj/$(SEEKDIR).o -c $(SEEKDIR).c $(CFLAGS) $(TELLDIR): $(TELLDIR).o $(GCC) -o $(TELLDIR) obj/$(TELLDIR).o $(LDFLAGS) $(TELLDIR).o: $(GCC) -o obj/$(TELLDIR).o -c $(TELLDIR).c $(CFLAGS) $(VERSIONSORT): $(VERSIONSORT).o $(GCC) -o $(VERSIONSORT) obj/$(VERSIONSORT).o $(LDFLAGS) $(VERSIONSORT).o: $(GCC) -o obj/$(VERSIONSORT).o -c $(VERSIONSORT).c $(CFLAGS)
#top Makefile.sol¶
SELECT ALL
# Project: Project # Makefile created GCC = gcc INCS = -DHAVE_FNMATCH=1 -DHAVE_GLOB=1 -DHAVE_MKDIR_MODE=1 -DHAVE_SCANDIR=1 CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long -D_FILE_OFFSET_BITS=64 -D_LINUX -D_REENTRANT CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long LIBS = LIBDIRS = LDFLAGS = $(LIBDIRS) $(LIBS) RM = rm -f MKDCMD = mkdir -p ALPHASORT = alphasort CHDIR = chdir CHROOT = chroot CLOSEDIR = closedir DIRFD = dirfd FDOPENDIR = fdopendir GETCWD = getcwd GETDIRENTRIES= getdirentries GLOB = glob GLOB_FNMATCH= glob-fnmatch GLOBFREE = globfree MKDIR = mkdir OPENDIR = opendir READDIR = readdir REWINDDIR = rewinddir RMDIR = rmdir SCANDIR = scandir SEEKDIR = seekdir TELLDIR = telldir VERSIONSORT = versionsort all: objdir make objdir: $(MKDCMD) obj/ clean: objdir $(RM) obj/*.o *.o *~ #make: $(ALPHASORT) #make: $(CHDIR) #make: $(CHROOT) #make: $(CLOSEDIR) #make: $(DIRFD) #make: $(FDOPENDIR) #make: $(GETCWD) #make: $(GETDIRENTRIES) #make: $(GLOB) #make: $(GLOB_FNMATCH) #make: $(GLOBFREE) #make: $(MKDIR) #make: $(OPENDIR) #make: $(READDIR) #make: $(REWINDDIR) #make: $(RMDIR) #make: $(SCANDIR) #make: $(SEEKDIR) #make: $(TELLDIR) #make: $(VERSIONSORT) make: $(ALPHASORT) $(CHDIR) $(CHROOT) $(CLOSEDIR) $(DIRFD) $(FDOPENDIR) $(GETCWD) $(GETDIRENTRIES) $(GLOB) $(GLOB_FNMATCH) $(GLOBFREE) $(MKDIR) $(OPENDIR) $(READDIR) $(REWINDDIR) $(RMDIR) $(SCANDIR) $(SEEKDIR) $(TELLDIR) $(VERSIONSORT) $(ALPHASORT): $(ALPHASORT).o $(GCC) -o $(ALPHASORT) obj/$(ALPHASORT).o $(LDFLAGS) $(ALPHASORT).o: $(GCC) -o obj/$(ALPHASORT).o -c $(ALPHASORT).c $(CFLAGS) $(CHDIR): $(CHDIR).o $(GCC) -o $(CHDIR) obj/$(CHDIR).o $(LDFLAGS) $(CHDIR).o: $(GCC) -o obj/$(CHDIR).o -c $(CHDIR).c $(CFLAGS) $(CHROOT): $(CHROOT).o $(GCC) -o $(CHROOT) obj/$(CHROOT).o $(LDFLAGS) $(CHROOT).o: $(GCC) -o obj/$(CHROOT).o -c $(CHROOT).c $(CFLAGS) $(CLOSEDIR): $(CLOSEDIR).o $(GCC) -o $(CLOSEDIR) obj/$(CLOSEDIR).o $(LDFLAGS) $(CLOSEDIR).o: $(GCC) -o obj/$(CLOSEDIR).o -c $(CLOSEDIR).c $(CFLAGS) $(DIRFD): $(DIRFD).o $(GCC) -o $(DIRFD) obj/$(DIRFD).o $(LDFLAGS) $(DIRFD).o: $(GCC) -o obj/$(DIRFD).o -c $(DIRFD).c $(CFLAGS) $(FDOPENDIR): $(FDOPENDIR).o $(GCC) -o $(FDOPENDIR) obj/$(FDOPENDIR).o $(LDFLAGS) $(FDOPENDIR).o: $(GCC) -o obj/$(FDOPENDIR).o -c $(FDOPENDIR).c $(CFLAGS) $(GETCWD): $(GETCWD).o $(GCC) -o $(GETCWD) obj/$(GETCWD).o $(LDFLAGS) $(GETCWD).o: $(GCC) -o obj/$(GETCWD).o -c $(GETCWD).c $(CFLAGS) $(GETDIRENTRIES): $(GETDIRENTRIES).o $(GCC) -o $(GETDIRENTRIES) obj/$(GETDIRENTRIES).o $(LDFLAGS) $(GETDIRENTRIES).o: $(GCC) -o obj/$(GETDIRENTRIES).o -c $(GETDIRENTRIES).c $(CFLAGS) $(GLOB): $(GLOB).o $(GCC) -o $(GLOB) obj/$(GLOB).o $(LDFLAGS) $(GLOB).o: $(GCC) -o obj/$(GLOB).o -c $(GLOB).c $(CFLAGS) $(GLOB_FNMATCH): $(GLOB_FNMATCH).o $(GCC) -o $(GLOB_FNMATCH) obj/$(GLOB_FNMATCH).o $(LDFLAGS) $(GLOB_FNMATCH).o: $(GCC) -o obj/$(GLOB_FNMATCH).o -c $(GLOB_FNMATCH).c $(CFLAGS) $(GLOBFREE): $(GLOBFREE).o $(GCC) -o $(GLOBFREE) obj/$(GLOBFREE).o $(LDFLAGS) $(GLOBFREE).o: $(GCC) -o obj/$(GLOBFREE).o -c $(GLOBFREE).c $(CFLAGS) $(MKDIR): $(MKDIR).o $(GCC) -o $(MKDIR) obj/$(MKDIR).o $(LDFLAGS) $(MKDIR).o: $(GCC) -o obj/$(MKDIR).o -c $(MKDIR).c $(CFLAGS) $(OPENDIR): $(OPENDIR).o $(GCC) -o $(OPENDIR) obj/$(OPENDIR).o $(LDFLAGS) $(OPENDIR).o: $(GCC) -o obj/$(OPENDIR).o -c $(OPENDIR).c $(CFLAGS) $(READDIR): $(READDIR).o $(GCC) -o $(READDIR) obj/$(READDIR).o $(LDFLAGS) $(READDIR).o: $(GCC) -o obj/$(READDIR).o -c $(READDIR).c $(CFLAGS) $(REWINDDIR): $(REWINDDIR).o $(GCC) -o $(REWINDDIR) obj/$(REWINDDIR).o $(LDFLAGS) $(REWINDDIR).o: $(GCC) -o obj/$(REWINDDIR).o -c $(REWINDDIR).c $(CFLAGS) $(RMDIR): $(RMDIR).o $(GCC) -o $(RMDIR) obj/$(RMDIR).o $(LDFLAGS) $(RMDIR).o: $(GCC) -o obj/$(RMDIR).o -c $(RMDIR).c $(CFLAGS) $(SCANDIR): $(SCANDIR).o $(GCC) -o $(SCANDIR) obj/$(SCANDIR).o $(LDFLAGS) $(SCANDIR).o: $(GCC) -o obj/$(SCANDIR).o -c $(SCANDIR).c $(CFLAGS) $(SEEKDIR): $(SEEKDIR).o $(GCC) -o $(SEEKDIR) obj/$(SEEKDIR).o $(LDFLAGS) $(SEEKDIR).o: $(GCC) -o obj/$(SEEKDIR).o -c $(SEEKDIR).c $(CFLAGS) $(TELLDIR): $(TELLDIR).o $(GCC) -o $(TELLDIR) obj/$(TELLDIR).o $(LDFLAGS) $(TELLDIR).o: $(GCC) -o obj/$(TELLDIR).o -c $(TELLDIR).c $(CFLAGS) $(VERSIONSORT): $(VERSIONSORT).o $(GCC) -o $(VERSIONSORT) obj/$(VERSIONSORT).o $(LDFLAGS) $(VERSIONSORT).o: $(GCC) -o obj/$(VERSIONSORT).o -c $(VERSIONSORT).c $(CFLAGS)
#top Makefile.beos¶
SELECT ALL
# Project: Project # Makefile created GCC = gcc INCS = -DHAVE_FDOPENDIR=1 -DHAVE_FNMATCH=1 -DHAVE_GLOB=1 -DHAVE_MKDIR_MODE=1 -DHAVE_VERSIONSORT=1 CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long -D_FILE_OFFSET_BITS=64 -D_LINUX -D_REENTRANT CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wno-long-long LIBS = LIBDIRS = LDFLAGS = $(LIBDIRS) $(LIBS) RM = rm -f MKDCMD = mkdir -p ALPHASORT = alphasort CHDIR = chdir CHROOT = chroot CLOSEDIR = closedir DIRFD = dirfd FDOPENDIR = fdopendir GETCWD = getcwd GETDIRENTRIES= getdirentries GLOB = glob GLOB_FNMATCH= glob-fnmatch GLOBFREE = globfree MKDIR = mkdir OPENDIR = opendir READDIR = readdir REWINDDIR = rewinddir RMDIR = rmdir SCANDIR = scandir SEEKDIR = seekdir TELLDIR = telldir VERSIONSORT = versionsort all: objdir make objdir: $(MKDCMD) obj/ clean: objdir $(RM) obj/*.o *.o *~ #make: $(ALPHASORT) #make: $(CHDIR) #make: $(CHROOT) #make: $(CLOSEDIR) #make: $(DIRFD) #make: $(FDOPENDIR) #make: $(GETCWD) #make: $(GETDIRENTRIES) #make: $(GLOB) #make: $(GLOB_FNMATCH) #make: $(GLOBFREE) #make: $(MKDIR) #make: $(OPENDIR) #make: $(READDIR) #make: $(REWINDDIR) #make: $(RMDIR) #make: $(SCANDIR) #make: $(SEEKDIR) #make: $(TELLDIR) #make: $(VERSIONSORT) make: $(ALPHASORT) $(CHDIR) $(CHROOT) $(CLOSEDIR) $(DIRFD) $(FDOPENDIR) $(GETCWD) $(GETDIRENTRIES) $(GLOB) $(GLOB_FNMATCH) $(GLOBFREE) $(MKDIR) $(OPENDIR) $(READDIR) $(REWINDDIR) $(RMDIR) $(SCANDIR) $(SEEKDIR) $(TELLDIR) $(VERSIONSORT) $(ALPHASORT): $(ALPHASORT).o $(GCC) -o $(ALPHASORT) obj/$(ALPHASORT).o $(LDFLAGS) $(ALPHASORT).o: $(GCC) -o obj/$(ALPHASORT).o -c $(ALPHASORT).c $(CFLAGS) $(CHDIR): $(CHDIR).o $(GCC) -o $(CHDIR) obj/$(CHDIR).o $(LDFLAGS) $(CHDIR).o: $(GCC) -o obj/$(CHDIR).o -c $(CHDIR).c $(CFLAGS) $(CHROOT): $(CHROOT).o $(GCC) -o $(CHROOT) obj/$(CHROOT).o $(LDFLAGS) $(CHROOT).o: $(GCC) -o obj/$(CHROOT).o -c $(CHROOT).c $(CFLAGS) $(CLOSEDIR): $(CLOSEDIR).o $(GCC) -o $(CLOSEDIR) obj/$(CLOSEDIR).o $(LDFLAGS) $(CLOSEDIR).o: $(GCC) -o obj/$(CLOSEDIR).o -c $(CLOSEDIR).c $(CFLAGS) $(DIRFD): $(DIRFD).o $(GCC) -o $(DIRFD) obj/$(DIRFD).o $(LDFLAGS) $(DIRFD).o: $(GCC) -o obj/$(DIRFD).o -c $(DIRFD).c $(CFLAGS) $(FDOPENDIR): $(FDOPENDIR).o $(GCC) -o $(FDOPENDIR) obj/$(FDOPENDIR).o $(LDFLAGS) $(FDOPENDIR).o: $(GCC) -o obj/$(FDOPENDIR).o -c $(FDOPENDIR).c $(CFLAGS) $(GETCWD): $(GETCWD).o $(GCC) -o $(GETCWD) obj/$(GETCWD).o $(LDFLAGS) $(GETCWD).o: $(GCC) -o obj/$(GETCWD).o -c $(GETCWD).c $(CFLAGS) $(GETDIRENTRIES): $(GETDIRENTRIES).o $(GCC) -o $(GETDIRENTRIES) obj/$(GETDIRENTRIES).o $(LDFLAGS) $(GETDIRENTRIES).o: $(GCC) -o obj/$(GETDIRENTRIES).o -c $(GETDIRENTRIES).c $(CFLAGS) $(GLOB): $(GLOB).o $(GCC) -o $(GLOB) obj/$(GLOB).o $(LDFLAGS) $(GLOB).o: $(GCC) -o obj/$(GLOB).o -c $(GLOB).c $(CFLAGS) $(GLOB_FNMATCH): $(GLOB_FNMATCH).o $(GCC) -o $(GLOB_FNMATCH) obj/$(GLOB_FNMATCH).o $(LDFLAGS) $(GLOB_FNMATCH).o: $(GCC) -o obj/$(GLOB_FNMATCH).o -c $(GLOB_FNMATCH).c $(CFLAGS) $(GLOBFREE): $(GLOBFREE).o $(GCC) -o $(GLOBFREE) obj/$(GLOBFREE).o $(LDFLAGS) $(GLOBFREE).o: $(GCC) -o obj/$(GLOBFREE).o -c $(GLOBFREE).c $(CFLAGS) $(MKDIR): $(MKDIR).o $(GCC) -o $(MKDIR) obj/$(MKDIR).o $(LDFLAGS) $(MKDIR).o: $(GCC) -o obj/$(MKDIR).o -c $(MKDIR).c $(CFLAGS) $(OPENDIR): $(OPENDIR).o $(GCC) -o $(OPENDIR) obj/$(OPENDIR).o $(LDFLAGS) $(OPENDIR).o: $(GCC) -o obj/$(OPENDIR).o -c $(OPENDIR).c $(CFLAGS) $(READDIR): $(READDIR).o $(GCC) -o $(READDIR) obj/$(READDIR).o $(LDFLAGS) $(READDIR).o: $(GCC) -o obj/$(READDIR).o -c $(READDIR).c $(CFLAGS) $(REWINDDIR): $(REWINDDIR).o $(GCC) -o $(REWINDDIR) obj/$(REWINDDIR).o $(LDFLAGS) $(REWINDDIR).o: $(GCC) -o obj/$(REWINDDIR).o -c $(REWINDDIR).c $(CFLAGS) $(RMDIR): $(RMDIR).o $(GCC) -o $(RMDIR) obj/$(RMDIR).o $(LDFLAGS) $(RMDIR).o: $(GCC) -o obj/$(RMDIR).o -c $(RMDIR).c $(CFLAGS) $(SCANDIR): $(SCANDIR).o $(GCC) -o $(SCANDIR) obj/$(SCANDIR).o $(LDFLAGS) $(SCANDIR).o: $(GCC) -o obj/$(SCANDIR).o -c $(SCANDIR).c $(CFLAGS) $(SEEKDIR): $(SEEKDIR).o $(GCC) -o $(SEEKDIR) obj/$(SEEKDIR).o $(LDFLAGS) $(SEEKDIR).o: $(GCC) -o obj/$(SEEKDIR).o -c $(SEEKDIR).c $(CFLAGS) $(TELLDIR): $(TELLDIR).o $(GCC) -o $(TELLDIR) obj/$(TELLDIR).o $(LDFLAGS) $(TELLDIR).o: $(GCC) -o obj/$(TELLDIR).o -c $(TELLDIR).c $(CFLAGS) $(VERSIONSORT): $(VERSIONSORT).o $(GCC) -o $(VERSIONSORT) obj/$(VERSIONSORT).o $(LDFLAGS) $(VERSIONSORT).o: $(GCC) -o obj/$(VERSIONSORT).o -c $(VERSIONSORT).c $(CFLAGS)
#top Makefile.win¶
SELECT ALL
# Project: Project # Makefile created GCC = gcc INCS = -DHAVE_VERSIONSORT=1 CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long -D_FILE_OFFSET_BITS=64 -D_LINUX -D_REENTRANT CFLAGS = $(INCS) -W -O2 -Wall -pedantic -Wstrict-aliasing -Wno-long-long LIBS = LIBDIRS = LDFLAGS = $(LIBDIRS) $(LIBS) RM = del /q /s MKDCMD = mkdir ALPHASORT = alphasort CHDIR = chdir CHROOT = chroot CLOSEDIR = closedir DIRFD = dirfd FDOPENDIR = fdopendir GETCWD = getcwd GETDIRENTRIES= getdirentries GLOB = glob GLOB_FNMATCH= glob-fnmatch GLOBFREE = globfree MKDIR = mkdir OPENDIR = opendir READDIR = readdir REWINDDIR = rewinddir RMDIR = rmdir SCANDIR = scandir SEEKDIR = seekdir TELLDIR = telldir VERSIONSORT = versionsort all: make objdir: $(MKDCMD) obj\ clean: $(RM) obj\*.o *.o *~ #make: $(ALPHASORT) #make: $(CHDIR) #make: $(CHROOT) #make: $(CLOSEDIR) #make: $(DIRFD) #make: $(FDOPENDIR) #make: $(GETCWD) #make: $(GETDIRENTRIES) #make: $(GLOB) #make: $(GLOB_FNMATCH) #make: $(GLOBFREE) #make: $(MKDIR) #make: $(OPENDIR) #make: $(READDIR) #make: $(REWINDDIR) #make: $(RMDIR) #make: $(SCANDIR) #make: $(SEEKDIR) #make: $(TELLDIR) #make: $(VERSIONSORT) make: $(ALPHASORT) $(CHDIR) $(CHROOT) $(CLOSEDIR) $(DIRFD) $(FDOPENDIR) $(GETCWD) $(GETDIRENTRIES) $(GLOB) $(GLOB_FNMATCH) $(GLOBFREE) $(MKDIR) $(OPENDIR) $(READDIR) $(REWINDDIR) $(RMDIR) $(SCANDIR) $(SEEKDIR) $(TELLDIR) $(VERSIONSORT) $(ALPHASORT): $(ALPHASORT).o $(GCC) -o $(ALPHASORT) obj/$(ALPHASORT).o $(LDFLAGS) $(ALPHASORT).o: $(GCC) -o obj/$(ALPHASORT).o -c $(ALPHASORT).c $(CFLAGS) $(CHDIR): $(CHDIR).o $(GCC) -o $(CHDIR) obj/$(CHDIR).o $(LDFLAGS) $(CHDIR).o: $(GCC) -o obj/$(CHDIR).o -c $(CHDIR).c $(CFLAGS) $(CHROOT): $(CHROOT).o $(GCC) -o $(CHROOT) obj/$(CHROOT).o $(LDFLAGS) $(CHROOT).o: $(GCC) -o obj/$(CHROOT).o -c $(CHROOT).c $(CFLAGS) $(CLOSEDIR): $(CLOSEDIR).o $(GCC) -o $(CLOSEDIR) obj/$(CLOSEDIR).o $(LDFLAGS) $(CLOSEDIR).o: $(GCC) -o obj/$(CLOSEDIR).o -c $(CLOSEDIR).c $(CFLAGS) $(DIRFD): $(DIRFD).o $(GCC) -o $(DIRFD) obj/$(DIRFD).o $(LDFLAGS) $(DIRFD).o: $(GCC) -o obj/$(DIRFD).o -c $(DIRFD).c $(CFLAGS) $(FDOPENDIR): $(FDOPENDIR).o $(GCC) -o $(FDOPENDIR) obj/$(FDOPENDIR).o $(LDFLAGS) $(FDOPENDIR).o: $(GCC) -o obj/$(FDOPENDIR).o -c $(FDOPENDIR).c $(CFLAGS) $(GETCWD): $(GETCWD).o $(GCC) -o $(GETCWD) obj/$(GETCWD).o $(LDFLAGS) $(GETCWD).o: $(GCC) -o obj/$(GETCWD).o -c $(GETCWD).c $(CFLAGS) $(GETDIRENTRIES): $(GETDIRENTRIES).o $(GCC) -o $(GETDIRENTRIES) obj/$(GETDIRENTRIES).o $(LDFLAGS) $(GETDIRENTRIES).o: $(GCC) -o obj/$(GETDIRENTRIES).o -c $(GETDIRENTRIES).c $(CFLAGS) $(GLOB): $(GLOB).o $(GCC) -o $(GLOB) obj/$(GLOB).o $(LDFLAGS) $(GLOB).o: $(GCC) -o obj/$(GLOB).o -c $(GLOB).c $(CFLAGS) $(GLOB_FNMATCH): $(GLOB_FNMATCH).o $(GCC) -o $(GLOB_FNMATCH) obj/$(GLOB_FNMATCH).o $(LDFLAGS) $(GLOB_FNMATCH).o: $(GCC) -o obj/$(GLOB_FNMATCH).o -c $(GLOB_FNMATCH).c $(CFLAGS) $(GLOBFREE): $(GLOBFREE).o $(GCC) -o $(GLOBFREE) obj/$(GLOBFREE).o $(LDFLAGS) $(GLOBFREE).o: $(GCC) -o obj/$(GLOBFREE).o -c $(GLOBFREE).c $(CFLAGS) $(MKDIR): $(MKDIR).o $(GCC) -o $(MKDIR) obj/$(MKDIR).o $(LDFLAGS) $(MKDIR).o: $(GCC) -o obj/$(MKDIR).o -c $(MKDIR).c $(CFLAGS) $(OPENDIR): $(OPENDIR).o $(GCC) -o $(OPENDIR) obj/$(OPENDIR).o $(LDFLAGS) $(OPENDIR).o: $(GCC) -o obj/$(OPENDIR).o -c $(OPENDIR).c $(CFLAGS) $(READDIR): $(READDIR).o $(GCC) -o $(READDIR) obj/$(READDIR).o $(LDFLAGS) $(READDIR).o: $(GCC) -o obj/$(READDIR).o -c $(READDIR).c $(CFLAGS) $(REWINDDIR): $(REWINDDIR).o $(GCC) -o $(REWINDDIR) obj/$(REWINDDIR).o $(LDFLAGS) $(REWINDDIR).o: $(GCC) -o obj/$(REWINDDIR).o -c $(REWINDDIR).c $(CFLAGS) $(RMDIR): $(RMDIR).o $(GCC) -o $(RMDIR) obj/$(RMDIR).o $(LDFLAGS) $(RMDIR).o: $(GCC) -o obj/$(RMDIR).o -c $(RMDIR).c $(CFLAGS) $(SCANDIR): $(SCANDIR).o $(GCC) -o $(SCANDIR) obj/$(SCANDIR).o $(LDFLAGS) $(SCANDIR).o: $(GCC) -o obj/$(SCANDIR).o -c $(SCANDIR).c $(CFLAGS) $(SEEKDIR): $(SEEKDIR).o $(GCC) -o $(SEEKDIR) obj/$(SEEKDIR).o $(LDFLAGS) $(SEEKDIR).o: $(GCC) -o obj/$(SEEKDIR).o -c $(SEEKDIR).c $(CFLAGS) $(TELLDIR): $(TELLDIR).o $(GCC) -o $(TELLDIR) obj/$(TELLDIR).o $(LDFLAGS) $(TELLDIR).o: $(GCC) -o obj/$(TELLDIR).o -c $(TELLDIR).c $(CFLAGS) $(VERSIONSORT): $(VERSIONSORT).o $(GCC) -o $(VERSIONSORT) obj/$(VERSIONSORT).o $(LDFLAGS) $(VERSIONSORT).o: $(GCC) -o obj/$(VERSIONSORT).o -c $(VERSIONSORT).c $(CFLAGS)
#top Predefined Constants¶
#top DT_***¶
Deklaracja stałych
DT_***
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja stałych
DT_***
jest następująca:/* File types for `d_type'. */ enum { DT_UNKNOWN = 0, # define DT_UNKNOWN DT_UNKNOWN DT_FIFO = 1, # define DT_FIFO DT_FIFO DT_CHR = 2, # define DT_CHR DT_CHR DT_DIR = 4, # define DT_DIR DT_DIR DT_BLK = 6, # define DT_BLK DT_BLK DT_REG = 8, # define DT_REG DT_REG DT_LNK = 10, # define DT_LNK DT_LNK DT_SOCK = 12, # define DT_SOCK DT_SOCK DT_WHT = 14 # define DT_WHT DT_WHT };
#top GLOB_***¶
Deklaracja stałych
GLOB_***
znajduje się w pliku nagłówkowym glob.h
.Deklaracja stałych
GLOB_***
jest następująca:/* Bits set in the FLAGS argument to `glob'. */ #define GLOB_ERR (1 << 0)/* Return on read errors. */ #define GLOB_MARK (1 << 1)/* Append a slash to each name. */ #define GLOB_NOSORT (1 << 2)/* Don't sort the names. */ #define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */ #define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */ #define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */ #define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */ #define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */ #if !defined __USE_POSIX2 || defined __USE_BSD || defined __USE_GNU # define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */ # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */ # define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */ # define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */ # define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */ # define GLOB_ONLYDIR (1 << 13)/* Match only directories. */ # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error if the user name is not available. */ # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \ GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK) #else # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ GLOB_PERIOD) #endif /* Error returns from `glob'. */ #define GLOB_NOSPACE 1 /* Ran out of memory. */ #define GLOB_ABORTED 2 /* Read error. */ #define GLOB_NOMATCH 3 /* No matches found. */ #define GLOB_NOSYS 4 /* Not implemented. */ #ifdef __USE_GNU /* Previous versions of this file defined GLOB_ABEND instead of GLOB_ABORTED. Provide a compatibility definition here. */ # define GLOB_ABEND GLOB_ABORTED #endif
#top Datatypes / MACROS¶
#top __blkcnt_t¶
Definicja typu
__blkcnt_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__blkcnt_t
jest następująca:/* Type to count number of disk blocks. */ __STD_TYPE __BLKCNT_T_TYPE __blkcnt_t; __STD_TYPE __BLKCNT64_T_TYPE __blkcnt64_t;
#top __blksize_t¶
Definicja typu
__blksize_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__blksize_t
jest następująca:/* Type to represent block size. */ __STD_TYPE __BLKSIZE_T_TYPE __blksize_t;
#top __dev_t¶
Definicja typu
__dev_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__dev_t
jest następująca:__STD_TYPE __DEV_T_TYPE __dev_t; /* Type of device numbers. */
#top __gid_t¶
Definicja typu
__gid_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__gid_t
jest następująca:__STD_TYPE __GID_T_TYPE __gid_t; /* Type of group identifications. */
#top __ino_t¶
Definicja typu
__ino_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__ino_t
jest następująca:__STD_TYPE __INO_T_TYPE __ino_t; /* Type of file serial numbers. */
#top __mode_t¶
Definicja typu
__mode_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__mode_t
jest następująca:__STD_TYPE __MODE_T_TYPE __mode_t; /* Type of file attribute bitmasks. */
#top __nlink_t¶
Definicja typu
__nlink_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__nlink_t
jest następująca:__STD_TYPE __NLINK_T_TYPE __nlink_t; /* Type of file link counts. */
#top __off_t¶
Definicja typu
__off_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__off_t
jest następująca:__STD_TYPE __OFF_T_TYPE __off_t; /* Type of file sizes and offsets. */
#top __size_t¶
Definicja typu
__size_t
znajduje się w pliku nagłówkowym glob.h
.Definicja typu
__size_t
jest następująca:/* We need `size_t' for the following definitions. */ #ifndef __size_t # if defined __GNUC__ && __GNUC__ >= 2 typedef __SIZE_TYPE__ __size_t; # ifdef __USE_XOPEN typedef __SIZE_TYPE__ size_t; # endif # else # include <stddef.h> # ifndef __size_t # define __size_t size_t # endif # endif #else /* The GNU CC stddef.h version defines __size_t as empty. We need a real definition. */ # undef __size_t # define __size_t size_t #endif
#top __ssize_t¶
Definicja typu
__ssize_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__ssize_t
jest następująca:__STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error. */
#top __time_t¶
Definicja typu
__time_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__time_t
jest następująca:__STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch. */
#top __uid_t¶
Definicja typu
__uid_t
znajduje się w pliku nagłówkowym bits/types.h
.Definicja typu
__uid_t
jest następująca:__STD_TYPE __UID_T_TYPE __uid_t; /* Type of user identifications. */
#top DIR¶
Definicja struktury
DIR
znajduje się w pliku nagłówkowym dirent.h
.Definicja struktury
DIR
jest następująca:/* This is the data type of directory stream objects. The actual structure is opaque to users. */ typedef struct __dirstream DIR;
#top glob_t¶
Definicja typu
glob_t
znajduje się w pliku nagłówkowym glob.h
.Definicja typu
glob_t
jest następująca:typedef struct { __size_t gl_pathc; :* Count of paths matched by the pattern. */ char **gl_pathv; /* List of matched pathnames. */ __size_t gl_offs; :* Slots to reserve in `gl_pathv'. */ int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */ /* If the GLOB_ALTDIRFUNC flag is set, the following functions are used instead of the normal file access functions. */ void (*gl_closedir) (void *); #ifdef __USE_GNU struct dirent *(*gl_readdir) (void *); #else void *(*gl_readdir) (void *); #endif void *(*gl_opendir) (__const char *); #ifdef __USE_GNU int (*gl_lstat) (__const char *__restrict, struct stat *__restrict); int (*gl_stat) (__const char *__restrict, struct stat *__restrict); #else int (*gl_lstat) (__const char *__restrict, void *__restrict); int (*gl_stat) (__const char *__restrict, void *__restrict); #endif } glob_t;
#top off_t¶
Definicja typu
off_t
znajduje się w pliku nagłówkowym unistd.h
.Definicja typu
off_t
znajduje się w pliku nagłówkowym sys/types.h
.Definicja typu
off_t
jest następująca:# ifndef __off_t_defined # ifndef __USE_FILE_OFFSET64 typedef __off_t off_t; # else typedef __off64_t off_t; # endif # define __off_t_defined # endif # if defined __USE_LARGEFILE64 && !defined __off64_t_defined typedef __off64_t off64_t; # define __off64_t_defined # endif
#top size_t¶
Definicja typu
size_t
znajduje się w pliku nagłówkowym /usr/lib/gcc/i386-redhat-linux/4.1.1/include/stddef.h
.Definicja typu
size_t
jest następująca:/* Unsigned type of `sizeof' something. */ /* Define this type if we are doing the whole job, or if we want this type in particular. */ #if defined (_STDDEF_H) || defined (__need_size_t) #ifndef __size_t__ /* BeOS */ #ifndef __SIZE_T__ /* Cray Unicos/Mk */ #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */ #ifndef _SYS_SIZE_T_H #ifndef _T_SIZE_ #ifndef _T_SIZE #ifndef __SIZE_T #ifndef _SIZE_T_ #ifndef _BSD_SIZE_T_ #ifndef _SIZE_T_DEFINED_ #ifndef _SIZE_T_DEFINED #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */ #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */ #ifndef ___int_size_t_h #ifndef _GCC_SIZE_T #ifndef _SIZET_ #ifndef __size_t #define __size_t__ /* BeOS */ #define __SIZE_T__ /* Cray Unicos/Mk */ #define _SIZE_T #define _SYS_SIZE_T_H #define _T_SIZE_ #define _T_SIZE #define __SIZE_T #define _SIZE_T_ #define _BSD_SIZE_T_ #define _SIZE_T_DEFINED_ #define _SIZE_T_DEFINED #define _BSD_SIZE_T_DEFINED_ /* Darwin */ #define _SIZE_T_DECLARED /* FreeBSD 5 */ #define ___int_size_t_h #define _GCC_SIZE_T #define _SIZET_ #if defined (__FreeBSD__) && (__FreeBSD__ >= 5) /* __size_t is a typedef on FreeBSD 5!, must not trash it. */ #else #define __size_t #endif #ifndef __SIZE_TYPE__ #define __SIZE_TYPE__ long unsigned int #endif #if !(defined (__GNUG__) && defined (size_t)) typedef __SIZE_TYPE__ size_t; #ifdef __BEOS__ typedef long ssize_t; #endif /* __BEOS__ */ #endif /* !(defined (__GNUG__) && defined (size_t)) */ #endif /* __size_t */ #endif /* _SIZET_ */ #endif /* _GCC_SIZE_T */ #endif /* ___int_size_t_h */ #endif /* _SIZE_T_DECLARED */ #endif /* _BSD_SIZE_T_DEFINED_ */ #endif /* _SIZE_T_DEFINED */ #endif /* _SIZE_T_DEFINED_ */ #endif /* _BSD_SIZE_T_ */ #endif /* _SIZE_T_ */ #endif /* __SIZE_T */ #endif /* _T_SIZE */ #endif /* _T_SIZE_ */ #endif /* _SYS_SIZE_T_H */ #endif /* _SIZE_T */ #endif /* __SIZE_T__ */ #endif /* __size_t__ */ #undef __need_size_t #endif /* _STDDEF_H or __need_size_t. */
#top struct dirent¶
Definicja struktury
struct dirent
znajduje się w pliku nagłówkowym bits/dirent.h
.Definicja struktury
struct dirent
jest następująca:struct dirent { #ifndef __USE_FILE_OFFSET64 __ino_t d_ino; __off_t d_off; #else __ino64_t d_ino; __off64_t d_off; #endif unsigned short int d_reclen; unsigned char d_type; char d_name[256]; /* We must not include limits.h! */ };
#top struct linux_dirent¶
Definicja struktury
struct linux_dirent
znajduje się w pliku nagłówkowym .h
.Definicja struktury
struct linux_dirent
jest następująca:struct linux_dirent { long d_ino; /* Inode number */ off_t d_off; :* Offset to next linux_dirent */ unsigned short d_reclen; /* Length of this linux_dirent */ char d_name[]; /* Filename (null-terminated) */ /* length is actually (d_reclen - 2 - offsetof(struct linux_dirent, d_name) */ /* char pad; // Zero padding byte * / char d_type; // File type (only since Linux 2.6.4; // offset is (d_reclen - 1)) */ };
#top struct stat¶
Definicja struktury
struct stat
znajduje się w pliku nagłówkowym bits/stat.h
.Definicja struktury
struct stat
jest następująca:struct stat { __dev_t st_dev; :* Device. */ unsigned short int __pad1; #ifndef __USE_FILE_OFFSET64 __ino_t st_ino; :* File serial number. */ #else __ino_t __st_ino; :* 32bit file serial number. */ #endif __mode_t st_mode; :* File mode. */ __nlink_t st_nlink; :* Link count. */ __uid_t st_uid; :* User ID of the file's owner. */ __gid_t st_gid; :* Group ID of the file's group.*/ __dev_t st_rdev; :* Device number, if device. */ unsigned short int __pad2; #ifndef __USE_FILE_OFFSET64 __off_t st_size; :* Size of file, in bytes. */ #else __off64_t st_size; /* Size of file, in bytes. */ #endif __blksize_t st_blksize; :* Optimal block size for I/O. */ #ifndef __USE_FILE_OFFSET64 __blkcnt_t st_blocks; :* Number 512-byte blocks allocated. */ #else __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */ #endif #ifdef __USE_MISC /* Nanosecond resolution timestamps are stored in a format equivalent to 'struct timespec'. This is the type used whenever possible but the Unix namespace rules do not allow the identifier 'timespec' to appear in the <sys/stat.h> header. Therefore we have to handle the use of this header in strictly standard-compliant sources special. */ struct timespec st_atim; :* Time of last access. */ struct timespec st_mtim; :* Time of last modification. */ struct timespec st_ctim; :* Time of last status change. */ # define st_atime st_atim.tv_sec /* Backward compatibility. */ # define st_mtime st_mtim.tv_sec # define st_ctime st_ctim.tv_sec #else __time_t st_atime; :* Time of last access. */ unsigned long int st_atimensec; /* Nscecs of last access. */ __time_t st_mtime; :* Time of last modification. */ unsigned long int st_mtimensec; /* Nsecs of last modification. */ __time_t st_ctime; :* Time of last status change. */ unsigned long int st_ctimensec; /* Nsecs of last status change. */ #endif #ifndef __USE_FILE_OFFSET64 unsigned long int __unused4; unsigned long int __unused5; #else __ino64_t st_ino; /* File serial number. */ #endif };
#top struct timespec¶
Definicja struktury
struct timespec
znajduje się w pliku nagłówkowym time.h
.Definicja struktury
struct timespec
jest następująca:/* POSIX.1b structure for a time value. This is like a `struct timeval' but has nanoseconds instead of microseconds. */ struct timespec { __time_t tv_sec; :* Seconds. */ long int tv_nsec; /* Nanoseconds. */ };
#top Directory Functions¶
#top alphasort¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
alphasort()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
alphasort()
jest następująca:/* Function to compare two `struct dirent's alphabetically. *: extern int alphasort (__const void *__e1, __const void *__e2) __THROW __attribute_pure__ __nonnull ((1, 2));
Powiązane:
alphasort(), getdents(), getdirentries(), glob(), globfree(), scandir(), versionsort(),
Opis:
Funkcja alphasort() została zaimplementowana w celu porównywania elementów typu struct dirent w funkcji sortującej umożliwiając tym samym sortowanie wyników zawartości katalogu (odczytanych funckją np: scandir() przyjmującą jako jeden z argumentów wskaźnik do funkcji porównującej kolejne elementy zawartości katalogu). Porównywanie realizowane jest poprzez wywoływanie funkcji strcoll() z argumentem d_name struktury struct dirent.
Argumenty:
const void *__e1 - element porównywany z elementem przekazanym w argumencie __e2.
const void *__e2 - element porównywany z elementem przekazanym w argumencie __e1.
Zwracana wartość:
int - wynik porównania pól d_name struktury struct dirent przekazanych do funkcji w argumentach wywołania __e1 i __e2.
Argumenty:
const void *__e1 - element porównywany z elementem przekazanym w argumencie __e2.
const void *__e2 - element porównywany z elementem przekazanym w argumencie __e1.
Zwracana wartość:
int - wynik porównania pól d_name struktury struct dirent przekazanych do funkcji w argumentach wywołania __e1 i __e2.
Example:
zawartość pliku
alphasort.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ int main(int argc, char **argv) { char *self; struct dirent **dirlist; struct dirent *dirrow; int result; int irow; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); return 0; } printf("%s: scandir( &alphasort ):\n", self); printf("%s: result=scandir(argv[1]=%s, &dirlist, NULL, &alphasort):\n", self, argv[1]); #if defined(HAVE_SCANDIR) result=scandir(argv[1], &dirlist, NULL, &alphasort); #else /* scandir() is not available on this OS platform !!! */ printf("%s: scandir() is not available on this OS platform !!!\n", self); result=-1; errno=ENOSYS; #endif if (result>=0) { printf("%s: result=scandir(argv[1]=%s, &dirlist, NULL, &alphasort): result=%d if (result>=0): Successful scandir().\n", self, argv[1], result); for (irow=0;irow<result;irow++) { dirrow=dirlist[irow]; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld\n", self, irow+1, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino); #else printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld\n", self, irow+1, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino); #endif } } else { printf("%s: dir=opendir(workdir=%s): result=%d if (dir != NULL): else: Unable to scandir(), Reason: %d:%s\n", self, argv[1], result, errno, strerror(errno)); } printf("\n"); printf("%s: scandir( &versionsort ):\n", self); printf("%s: result=scandir(argv[1]=%s, &dirlist, NULL, &versionsort):\n", self, argv[1]); #if defined(HAVE_SCANDIR) result=scandir(argv[1], &dirlist, NULL, &versionsort); #else /* scandir() is not available on this OS platform !!! */ printf("%s: scandir() is not available on this OS platform !!!\n", self); result=-1; errno=ENOSYS; #endif if (result>=0) { printf("%s: result=scandir(argv[1]=%s, &dirlist, NULL, &versionsort): result=%d if (result>=0): Successful scandir().\n", self, argv[1], result); for (irow=0;irow<result;irow++) { dirrow=dirlist[irow]; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld\n", self, irow+1, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino); #else printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld\n", self, irow+1, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino); #endif } } else { printf("%s: dir=opendir(workdir=%s): result=%d if (dir != NULL): else: Unable to scandir(), Reason: %d:%s\n", self, argv[1], result, errno, strerror(errno)); } printf("\n"); return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/alphasortprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/alphasort </path/to/directory>
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/alphasort /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
alphasort: scandir( &alphasort ): alphasort: result=scandir(argv[1]=/home/local/code/ansiccode/sysdir, &dirlist, NULL, &alphasort): alphasort: result=scandir(argv[1]=/home/local/code/ansiccode/sysdir, &dirlist, NULL, &alphasort): result=45 if (result>=0): Successful scandir(). alphasort: [01] dirrow->d_name=. dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2115597079 dirrow->d_ino=1410666 alphasort: [02] dirrow->d_name=.. dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=1383606058 dirrow->d_ino=1410182 alphasort: [03] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1707577288 dirrow->d_ino=1410658 alphasort: [04] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410522 alphasort: [05] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1853408271 dirrow->d_ino=1410240 alphasort: [06] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2007201532 dirrow->d_ino=1410275 alphasort: [07] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=130721592 dirrow->d_ino=1410535 alphasort: [08] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410538 alphasort: [09] dirrow->d_name=alphasort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1903302723 dirrow->d_ino=1410358 alphasort: [10] dirrow->d_name=alphasort.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=427406474 dirrow->d_ino=1411008 alphasort: [11] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 alphasort: [12] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=687030437 dirrow->d_ino=1410448 alphasort: [13] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 alphasort: [14] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 alphasort: [15] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 alphasort: [16] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 alphasort: [17] dirrow->d_name=dirfd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410758 alphasort: [18] dirrow->d_name=dirfd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=714692598 dirrow->d_ino=1411007 alphasort: [19] dirrow->d_name=fdopendir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410972 alphasort: [20] dirrow->d_name=fdopendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=718026284 dirrow->d_ino=1410990 alphasort: [21] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1336351603 dirrow->d_ino=1410440 alphasort: [22] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 alphasort: [23] dirrow->d_name=getdirentries dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1964717140 dirrow->d_ino=1410996 alphasort: [24] dirrow->d_name=getdirentries.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1638081534 dirrow->d_ino=1410377 alphasort: [25] dirrow->d_name=glob dirrow->d_type=0x08 dirrow->d_reclen=16 dirrow->d_off=1345128052 dirrow->d_ino=1411025 alphasort: [26] dirrow->d_name=glob.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=340175332 dirrow->d_ino=1411054 alphasort: [27] dirrow->d_name=mkdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1709357308 dirrow->d_ino=1411037 alphasort: [28] dirrow->d_name=mkdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1771880146 dirrow->d_ino=1411061 alphasort: [29] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 alphasort: [30] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=361703713 dirrow->d_ino=1410445 alphasort: [31] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 alphasort: [32] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 alphasort: [33] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=326292342 dirrow->d_ino=1410387 alphasort: [34] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 alphasort: [35] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1558810147 dirrow->d_ino=1409388 alphasort: [36] dirrow->d_name=rmdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1934495362 dirrow->d_ino=1411048 alphasort: [37] dirrow->d_name=rmdir.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=2010445905 dirrow->d_ino=1411023 alphasort: [38] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 alphasort: [39] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1423750639 dirrow->d_ino=1410392 alphasort: [40] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 alphasort: [41] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 alphasort: [42] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 alphasort: [43] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 alphasort: [44] dirrow->d_name=versionsort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1411053 alphasort: [45] dirrow->d_name=versionsort.c dirrow->d_type=0x0A dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1411051 alphasort: scandir( &versionsort ): alphasort: result=scandir(argv[1]=/home/local/code/ansiccode/sysdir, &dirlist, NULL, &versionsort): alphasort: result=scandir(argv[1]=/home/local/code/ansiccode/sysdir, &dirlist, NULL, &versionsort): result=45 if (result>=0): Successful scandir(). alphasort: [01] dirrow->d_name=. dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2115597079 dirrow->d_ino=1410666 alphasort: [02] dirrow->d_name=.. dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=1383606058 dirrow->d_ino=1410182 alphasort: [03] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1707577288 dirrow->d_ino=1410658 alphasort: [04] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410522 alphasort: [05] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1853408271 dirrow->d_ino=1410240 alphasort: [06] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2007201532 dirrow->d_ino=1410275 alphasort: [07] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=130721592 dirrow->d_ino=1410535 alphasort: [08] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410538 alphasort: [09] dirrow->d_name=alphasort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1903302723 dirrow->d_ino=1410358 alphasort: [10] dirrow->d_name=alphasort.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=427406474 dirrow->d_ino=1411008 alphasort: [11] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 alphasort: [12] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=687030437 dirrow->d_ino=1410448 alphasort: [13] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 alphasort: [14] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 alphasort: [15] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 alphasort: [16] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 alphasort: [17] dirrow->d_name=dirfd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410758 alphasort: [18] dirrow->d_name=dirfd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=714692598 dirrow->d_ino=1411007 alphasort: [19] dirrow->d_name=fdopendir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410972 alphasort: [20] dirrow->d_name=fdopendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=718026284 dirrow->d_ino=1410990 alphasort: [21] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1336351603 dirrow->d_ino=1410440 alphasort: [22] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 alphasort: [23] dirrow->d_name=getdirentries dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1964717140 dirrow->d_ino=1410996 alphasort: [24] dirrow->d_name=getdirentries.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1638081534 dirrow->d_ino=1410377 alphasort: [25] dirrow->d_name=glob dirrow->d_type=0x08 dirrow->d_reclen=16 dirrow->d_off=1345128052 dirrow->d_ino=1411025 alphasort: [26] dirrow->d_name=glob.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=340175332 dirrow->d_ino=1411054 alphasort: [27] dirrow->d_name=mkdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1709357308 dirrow->d_ino=1411037 alphasort: [28] dirrow->d_name=mkdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1771880146 dirrow->d_ino=1411061 alphasort: [29] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 alphasort: [30] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=361703713 dirrow->d_ino=1410445 alphasort: [31] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 alphasort: [32] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 alphasort: [33] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=326292342 dirrow->d_ino=1410387 alphasort: [34] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 alphasort: [35] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1558810147 dirrow->d_ino=1409388 alphasort: [36] dirrow->d_name=rmdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1934495362 dirrow->d_ino=1411048 alphasort: [37] dirrow->d_name=rmdir.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=2010445905 dirrow->d_ino=1411023 alphasort: [38] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 alphasort: [39] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1423750639 dirrow->d_ino=1410392 alphasort: [40] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 alphasort: [41] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 alphasort: [42] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 alphasort: [43] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 alphasort: [44] dirrow->d_name=versionsort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1411053 alphasort: [45] dirrow->d_name=versionsort.c dirrow->d_type=0x0A dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1411051
#top chdir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
chdir()
znajduje się w pliku nagłówkowym unistd.h
.Deklaracja funkcji
chdir()
jest następująca:/* Change the process's working directory to PATH. */ extern int chdir (__const char *__path) __THROW __nonnull ((1)) __wur;
Powiązane:
chdir(), chroot(), getcwd(),
Opis:
Funkcja chdir() zmienia bieżący katalog na katalog podany w argumencie wywołania __path. W przypadku sukcesu zwraca wartość 0, w przeciwnym przypadku zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający ścieżkę do katalogu, który zostanie ustawiony jako bieżący katalog.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający ścieżkę do katalogu, który zostanie ustawiony jako bieżący katalog.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
Example:
zawartość pliku
chdir.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ int main(int argc, char **argv) { char *self; char buffpath[1024], *buffptrs; int result; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); return 0; } memset(buffpath, 0x00, sizeof(buffpath)); printf("%s: buffptrs=getcwd(buffpath, sizeof(buffpath)=%lu):\n", self, (unsigned long int)sizeof(buffpath)); buffptrs=getcwd(buffpath, sizeof(buffpath)); printf("%s: buffptrs=|%s| buffpath=|%s|\n", self, buffptrs, buffpath); printf("%s: result=chdir(argv[1]=%s):\n", self, argv[1]); result=chdir(argv[1]); if (result>=0) printf("%s: result=chdir(argv[1]=%s): result=%d if (result>=0): Successful chdir().\n", self, argv[1], result); else printf("%s: result=chdir(argv[1]=%s): result=%d if (result>=0): else: Unable to chdir(), Reason: %d:%s\n", self, argv[1], result, errno, strerror(errno)); memset(buffpath, 0x00, sizeof(buffpath)); printf("%s: buffptrs=getcwd(buffpath, sizeof(buffpath)=%lu):\n", self, (unsigned long int)sizeof(buffpath)); buffptrs=getcwd(buffpath, sizeof(buffpath)); printf("%s: buffptrs=|%s| buffpath=|%s|\n", self, buffptrs, buffpath); return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/chdirprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/chdir </path/to/directory>
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/chdir /home/local/code/ansiccode/sysdir /home/local/code/ansiccode/sysdir/chdir /root /home/local/code/ansiccode/sysdir/chdir /etc/fstabrezultat będzie zależny od podanych argumentów wywołania programu:
chdir: buffptrs=getcwd(buffpath, sizeof(buffpath)=1024): chdir: buffptrs=|/home/user| buffpath=|/home/user| chdir: result=chdir(argv[1]=/home/local/code/ansiccode/sysdir): chdir: result=chdir(argv[1]=/home/local/code/ansiccode/sysdir): result=0 if (result>=0): Successful chdir(). chdir: buffptrs=getcwd(buffpath, sizeof(buffpath)=1024): chdir: buffptrs=|/home/local/code/ansiccode/sysdir| buffpath=|/home/local/code/ansiccode/sysdir| chdir: buffptrs=getcwd(buffpath, sizeof(buffpath)=1024): chdir: buffptrs=|/home/user| buffpath=|/home/user| chdir: result=chdir(argv[1]=/root): chdir: result=chdir(argv[1]=/root): result=-1 if (result>=0): else: Unable to chdir(), Reason: 13:Permission denied chdir: buffptrs=getcwd(buffpath, sizeof(buffpath)=1024): chdir: buffptrs=|/home/user| buffpath=|/home/user| chdir: buffptrs=getcwd(buffpath, sizeof(buffpath)=1024): chdir: buffptrs=|/home/user| buffpath=|/home/user| chdir: result=chdir(argv[1]=/etc/fstab): chdir: result=chdir(argv[1]=/etc/fstab): result=-1 if (result>=0): else: Unable to chdir(), Reason: 20:Not a directory chdir: buffptrs=getcwd(buffpath, sizeof(buffpath)=1024): chdir: buffptrs=|/home/user| buffpath=|/home/user|
#top chroot¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
chroot()
znajduje się w pliku nagłówkowym unistd.h
.Deklaracja funkcji
chroot()
jest następująca:/* Make PATH be the root directory (the starting point for absolute paths). This call is restricted to the super-user. */ extern int chroot (__const char *__path) __THROW __nonnull ((1)) __wur;
Powiązane:
chdir(), chroot(), getcwd(),
Opis:
Funkcja chroot() zmienia katalog główny na katalog podany w argumencie wywołania __path. W przypadku sukcesu zwraca wartość 0, w przeciwnym przypadku zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający ścieżkę do katalogu, który zostanie ustawiony jako katalog główny.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający ścieżkę do katalogu, który zostanie ustawiony jako katalog główny.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
Example:
zawartość pliku
chroot.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdlib.h> /* for RAND_MAX, EXIT_FAILURE, EXIT_SUCCESS, MB_CUR_MAX, atoi(), atol(), atoll(), atof(), strtod(), strtof(), strtold(), strtol(), strtoul(), strtoq(), strtouq(), strtoll(), strtoull(), */ /* for sys/types.h, malloc.h replaced by stdlib.h, random(), srandom(), rand(), srand(), abort(), atexit(), on_exit(), exit(), getenv(), */ /* for putenv(), setenv(), clearenv(), mktemp(), mkstemp(), mkdtemp(), system(), realpath(), abs(), labs(), llabs(), getloadavg(), */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include <winsock.h> /* for SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, AF_INET, PF_INET, socket(), connect(), send(), recv(), sendto(), recvfrom(), shutdown(), */ /* for bind(), listen(), accept(), getsockname(), getsockopt(), setsockopt(), */ /* for in_addr_t, INADDR_ANY, INADDR_NONE, INADDR_BROADCAST, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_ICMP, IPPROTO_RAW, */ /* for struct sockaddr_in, struct in_addr, inet_addr(), struct hostent, gethostbyname(), gethostbyaddr(), */ #endif #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) /* Sleep - Capital first letter */ /* #include <windows.h> + #include <winbase.h> +++ -lws_32 */ #define sleep(time) Sleep(1000*time) #define usleep(useconds) Sleep((useconds+999) / 1000) #endif int main(int argc, char **argv) { char *self; #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) #else int result; #endif self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/dir>\n", argv[0]); return 0; } #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) /* chroot() is not available on this OS platform !!! */ printf("%s: chroot() is not available on this OS platform !!!\n", self); #else result=chroot(argv[1]); if (result>=0) printf("%s: result=chroot(argv[1]=%s): result=%d if (result>=0): Successful chroot().\n", self, argv[1], result); else printf("%s: result=chroot(argv[1]=%s): result=%d if (result>=0): else: Unable to chroot(), Reason: %d:%s\n", self, argv[1], result, errno, strerror(errno)); #endif printf("%s: sleep(30);\n", self); sleep(30); return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/chrootprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/chroot </path/to/dir>
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/chroot /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
chroot: result=chroot(argv[1]=/home/local/code/ansiccode/sysdir): result=-1 if (result>=0): else: Unable to chroot(), Reason: 1:Operation not permitted chroot: sleep(30);jak widać w powyższym przykładzie rezultat wywołania programu jest negatywny, wywołania
chroot()
wymaga uprawnień, po uruchomieniu programu jako użytkownik root uzyskany zostanie następujący rezultat:chroot: result=chroot(argv[1]=/home/local/code/ansiccode/sysdir): result=0 if (result>=0): Successful chroot(). chroot: sleep(30);
#top closedir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
closedir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
closedir()
jest następująca:/* Close the directory stream DIRP. Return 0 if successful, -1 if not. This function is a possible cancellation point and therefore not marked with __THROW. */ extern int closedir (DIR *__dirp) __nonnull ((1));
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja closedir() zamyka deskryptor katalogu przekazany w argumencie wywołania __dirp. W przypadku sukcesu zwraca wartość 0, w przeciwnym przypadku zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
DIR *__dirp - deskryptor katalogu do zamknięcia.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
Argumenty:
DIR *__dirp - deskryptor katalogu do zamknięcia.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
#top dirfd¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
dirfd()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
dirfd()
jest następująca:/* Return the file descriptor used by DIRP. */ extern int dirfd (DIR *__dirp) __THROW __nonnull ((1));
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja dirfd() zwraca deskryptor katalogu wskazujący na ten sam katalog jak deskryptor podany w argumencie __dirp. Zwrócony deskryptor katalogu może być przekazany jako argument wywołania funkcji getdents() lub getdirentries() operującej na katalogu. W przypadku sukcesu funkcja zwraca deskryptor do katalogu, w przeciwnym razie zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
DIR *__dirp - deskryptor do katalogu.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
Argumenty:
DIR *__dirp - deskryptor do katalogu.
Zwracana wartość:
int - rezultat wykonania operacji zmiany katalogu: 0 w przypadku sukcesu, -1 w przypadku niepowodzenia.
#top fdopendir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
fdopendir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
fdopendir()
jest następująca:/* Same as opendir, but open the stream on the file descriptor FD. This function is a possible cancellation point and therefore not marked with __THROW. */ extern DIR *fdopendir (int __fd);
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja fdopendir() zwraca deskryptor katalogu wskazujący na ten sam katalog jak deskryptor podany w argumencie __fd. Zwrócony deskryptor katalogu może być przekazany jako argument wywołania funkcji closedir(), opendir(), readdir(), rewinddir(), seekdir(), telldir() operujących na katalogu. W przypadku sukcesu funkcja zwraca deskryptor do katalogu, w przeciwnym razie zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
int __fd -
Zwracana wartość:
DIR * -
Argumenty:
int __fd -
Zwracana wartość:
DIR * -
Example:
zawartość pliku
fdopendir.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(), getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include <fcntl.h> /* for io.h, O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND, */ #else #include <fcntl.h> /* for O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND, F_GETFL, F_SETFL, O_NONBLOCK, O_SYNC, FASYNC, O_DIRECT, O_LARGEFILE, O_DIRECTORY, O_NOFOLLOW, O_NOATIME, O_NDELAY, */ /* for LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN, LOCK_MAND, LOCK_READ, LOCK_WRITE, LOCK_RW, fcntl(), open(), creat(), */ #endif int main(int argc, char **argv) { char *self; int fprd1, fprd2; #if defined(HAVE_FDOPENDIR) DIR *dirfd1, *dirfd2; struct dirent *dirrow; int result; int irow; #endif self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); printf("Examples:\n"); printf(" %s /home/local/code/ansiccode/sysdir\n", argv[0]); return 0; } fprd1=fprd2=-1; fprd1=open(argv[1], O_RDONLY, 0644); if (fprd1>=0) { printf("%s: fprd1=open(argv[1]=%s, O_RDONLY=%d, 0644); fprd1=%d if (fprd1>=0): Successful open() file.\n", self, argv[1], O_RDONLY, fprd1); #if defined(HAVE_FDOPENDIR) dirfd1=fdopendir(fprd1); if (dirfd1 != NULL) { printf("%s: dirfd1=fdopendir(fprd1=%d): dirfd1=%p if (dirfd1 != NULL): Successful fdopendir().\n", self, fprd1, (void*)dirfd1); irow=0; printf("%s: while ((dirrow=readdir(dirfd1)) != NULL):\n", self); while ((dirrow=readdir(dirfd1)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd1)=%ld\n", self, irow++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd1)); #else printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd1)=%ld\n", self, irow++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd1)); #endif } fprd2=dirfd(dirfd1); if (fprd2>=0) { printf("%s: fprd2=dirfd(dirfd1=%p); fprd2=%d if (fprd1>=0): Successful dirfd().\n", self, (void*)dirfd1, fprd2); dirfd2=fdopendir(fprd2); if (dirfd2 != NULL) { printf("%s: dirfd2=fdopendir(fprd2=%d): dirfd2=%p if (dirfd2 != NULL): Successful fdopendir().\n", self, fprd2, (void*)dirfd2); irow=0; printf("%s: while ((dirrow=readdir(dirfd2)) != NULL):\n", self); while ((dirrow=readdir(dirfd2)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd2)=%ld\n", self, irow++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd2)); #else printf("%s: [%02d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd2)=%ld\n", self, irow++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd2)); #endif } result=closedir(dirfd2); if (result>=0) printf("%s: result=closedir(dirfd2=%p): result=%d if (result>=0): Successful closedir().\n", self, (void*)dirfd2, result); else printf("%s: result=closedir(dirfd2=%p): result=%d if (result>=0): else: Unable to closedir(), Reason: %d:%s\n", self, (void*)dirfd2, result, errno, strerror(errno)); } else { printf("%s: dirfd2=fdopendir(fprd2=%d): dirfd2=%p if (dirfd2 != NULL): else: Unable to fdopendir(), Reason: %d:%s\n", self, fprd2, (void*)dirfd2, errno, strerror(errno)); } result=close(fprd2); if (result>=0) printf("%s: result=close(fprd2=%d); result=%d if (result>=0): Successful close() file.\n", self, fprd2, result); else printf("%s: result=close(fprd2=%d); result=%d if (result>=0): else: Unable to close() file, Reason=%d:%s\n", self, fprd2, result, errno, strerror(errno)); } else { printf("%s: fprd2=dirfd(dirfd1=%p); fprd2=%d if (fprd1>=0): else: Unable to dirfd(), Reason: %d:%s.\n", self, (void*)dirfd1, fprd2, errno, strerror(errno)); } result=closedir(dirfd1); if (result>=0) printf("%s: result=closedir(dirfd1): result=%d if (result>=0): Successful closedir().\n", self, result); else printf("%s: result=closedir(dirfd1): result=%d if (result>=0): else: Unable to closedir(), Reason: %d:%s\n", self, result, errno, strerror(errno)); } else { printf("%s: dirfd1=fdopendir(fprd1=%d): dirfd1=%p if (dirfd1 != NULL): else: Unable to fdopendir(), Reason: %d:%s\n", self, fprd1, (void*)dirfd1, errno, strerror(errno)); } result=close(fprd1); if (result>=0) printf("%s: result=close(fprd1=%d); result=%d if (result>=0): Successful close() file.\n", self, fprd1, result); else printf("%s: result=close(fprd1=%d); result=%d if (result>=0): else: Unable to close() file, Reason=%d:%s\n", self, fprd1, result, errno, strerror(errno)); #endif /* HAVE_FDOPENDIR */ } else { printf("%s: fprd1=open(argv[1]=%s, O_RDONLY=%d, 0644); fprd1=%d if (fprd1>=0): else: Unable to open() file, Reason: %d:%s\n", self, argv[1], O_RDONLY, fprd1, errno, strerror(errno)); } return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/fdopendirprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/fdopendir </path/to/directory> Examples: /home/local/code/ansiccode/sysdir/fdopendir /home/local/code/ansiccode/sysdir
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/fdopendir /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
fdopendir: fprd1=open(argv[1]=/home/local/code/ansiccode/sysdir, O_RDONLY=0, 0644); fprd1=3 if (fprd1>=0): Successful open() file. fdopendir: dirfd1=fdopendir(fprd1=3): dirfd1=0x8827008 if (dirfd1 != NULL): Successful fdopendir(). fdopendir: while ((dirrow=readdir(dirfd1)) != NULL): fdopendir: [00] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 telldir(dirfd1)=111075960 fdopendir: [01] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=118909187 dirrow->d_ino=1410401 telldir(dirfd1)=118909187 fdopendir: [02] dirrow->d_name=globfree.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=123907409 dirrow->d_ino=1411134 telldir(dirfd1)=123907409 fdopendir: [03] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=130721592 dirrow->d_ino=1410657 telldir(dirfd1)=130721592 fdopendir: [04] dirrow->d_name=versionsort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1411053 telldir(dirfd1)=147508333 fdopendir: [05] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 telldir(dirfd1)=258066785 fdopendir: [06] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=326292342 dirrow->d_ino=1410387 telldir(dirfd1)=326292342 fdopendir: [07] dirrow->d_name=glob.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=340175332 dirrow->d_ino=1411054 telldir(dirfd1)=340175332 fdopendir: [08] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=361703713 dirrow->d_ino=1410445 telldir(dirfd1)=361703713 fdopendir: [09] dirrow->d_name=alphasort.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=427406474 dirrow->d_ino=1411008 telldir(dirfd1)=427406474 fdopendir: [10] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 telldir(dirfd1)=495216175 fdopendir: [11] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 telldir(dirfd1)=625605754 fdopendir: [12] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1410495 telldir(dirfd1)=661949438 fdopendir: [13] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410253 telldir(dirfd1)=679195114 fdopendir: [14] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 telldir(dirfd1)=679233412 fdopendir: [15] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=687030437 dirrow->d_ino=1410448 telldir(dirfd1)=687030437 fdopendir: [16] dirrow->d_name=dirfd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=714692598 dirrow->d_ino=1411007 telldir(dirfd1)=714692598 fdopendir: [17] dirrow->d_name=fdopendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=718026284 dirrow->d_ino=1410990 telldir(dirfd1)=718026284 fdopendir: [18] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 telldir(dirfd1)=753056283 fdopendir: [19] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 telldir(dirfd1)=866081774 fdopendir: [20] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 telldir(dirfd1)=1049513945 fdopendir: [21] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 telldir(dirfd1)=1165269826 fdopendir: [22] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 telldir(dirfd1)=1166638244 fdopendir: [23] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1172385886 dirrow->d_ino=1410440 telldir(dirfd1)=1172385886 fdopendir: [24] dirrow->d_name=globfree dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1336351603 dirrow->d_ino=1411148 telldir(dirfd1)=1336351603 fdopendir: [25] dirrow->d_name=glob dirrow->d_type=0x08 dirrow->d_reclen=16 dirrow->d_off=1345128052 dirrow->d_ino=1411025 telldir(dirfd1)=1345128052 fdopendir: [26] dirrow->d_name=glob-fnmatch dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1383606058 dirrow->d_ino=1411050 telldir(dirfd1)=1383606058 fdopendir: [27] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1423750639 dirrow->d_ino=1410392 telldir(dirfd1)=1423750639 fdopendir: [28] dirrow->d_name=fdopendir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410972 telldir(dirfd1)=1481921411 fdopendir: [29] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1558810147 dirrow->d_ino=1409388 telldir(dirfd1)=1558810147 fdopendir: [30] dirrow->d_name=getdirentries.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1603650525 dirrow->d_ino=1410377 telldir(dirfd1)=1603650525 fdopendir: [31] dirrow->d_name=glob-fnmatch.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1638081534 dirrow->d_ino=1411180 telldir(dirfd1)=1638081534 fdopendir: [32] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1707577288 dirrow->d_ino=1410458 telldir(dirfd1)=1707577288 fdopendir: [33] dirrow->d_name=mkdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1709357308 dirrow->d_ino=1411037 telldir(dirfd1)=1709357308 fdopendir: [34] dirrow->d_name=mkdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1771880146 dirrow->d_ino=1411061 telldir(dirfd1)=1771880146 fdopendir: [35] dirrow->d_name=dirfd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410758 telldir(dirfd1)=1786084748 fdopendir: [36] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 telldir(dirfd1)=1788532095 fdopendir: [37] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1853408271 dirrow->d_ino=1410234 telldir(dirfd1)=1853408271 fdopendir: [38] dirrow->d_name=alphasort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1903302723 dirrow->d_ino=1410274 telldir(dirfd1)=1903302723 fdopendir: [39] dirrow->d_name=rmdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1934495362 dirrow->d_ino=1411048 telldir(dirfd1)=1934495362 fdopendir: [40] dirrow->d_name=getdirentries dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1964717140 dirrow->d_ino=1410996 telldir(dirfd1)=1964717140 fdopendir: [41] dirrow->d_name=versionsort.c dirrow->d_type=0x0A dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1411051 telldir(dirfd1)=1967637597 fdopendir: [42] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2007201532 dirrow->d_ino=1410221 telldir(dirfd1)=2007201532 fdopendir: [43] dirrow->d_name=rmdir.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=2010445905 dirrow->d_ino=1411023 telldir(dirfd1)=2010445905 fdopendir: [44] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 telldir(dirfd1)=2069417274 fdopendir: [45] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 telldir(dirfd1)=2099643303 fdopendir: [46] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410506 telldir(dirfd1)=2147483647 fdopendir: fprd2=dirfd(dirfd1=0x8827008); fprd2=3 if (fprd1>=0): Successful dirfd(). fdopendir: dirfd2=fdopendir(fprd2=3): dirfd2=0x8828028 if (dirfd2 != NULL): Successful fdopendir(). fdopendir: while ((dirrow=readdir(dirfd2)) != NULL): fdopendir: result=closedir(dirfd2=0x8828028): result=0 if (result>=0): Successful closedir(). fdopendir: result=close(fprd2=3); result=-1 if (result>=0): else: Unable to close() file, Reason=9:Bad file descriptor fdopendir: result=closedir(dirfd1): result=-1 if (result>=0): else: Unable to closedir(), Reason: 9:Bad file descriptor fdopendir: result=close(fprd1=3); result=-1 if (result>=0): else: Unable to close() file, Reason=9:Bad file descriptor
#top getcwd¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
getcwd()
znajduje się w pliku nagłówkowym unistd.h
.Deklaracja funkcji
getcwd()
jest następująca:/* Get the pathname of the current working directory, and put it in SIZE bytes of BUF. Returns NULL if the directory couldn't be determined or SIZE was too small. If successful, returns BUF. In GNU, if BUF is NULL, an array is allocated with `malloc'; the array is SIZE bytes long, unless SIZE == 0, in which case it is as big as necessary. */ extern char *getcwd (char *__buf, size_t __size) __THROW __wur;
Powiązane:
chdir(), chroot(), getcwd(),
Opis:
Funkcja getcwd() zwraca łańcuch znaków (wskaźnik do łańcucha znaków) przekazany w argumencie __buf (w przypadku gdy nie jest on
Argumenty:
char *__buf - łańcuch znaków (wskaźnik do bufora na łańcucha znaków) w którym umieszczona zostanie ścieżka do bieżącego katalogu.
size_t __size - rozmiar bufora na łańcuch znaków przekazany w argumencie __buf.
Zwracana wartość:
char * - łańcuch znaków (wskaźnik do łańcucha znaków) przekazany w argumencie __buf (w przypadku gdy nie jest on
NULL
) zawierający ścieżkę do bieżącego katalogu. W przypadku sukcesu zwraca łańcuch znaków (wskaźnik do łańcucha znaków), w przeciwnym przypadku zwraca wartość NULL oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.Argumenty:
char *__buf - łańcuch znaków (wskaźnik do bufora na łańcucha znaków) w którym umieszczona zostanie ścieżka do bieżącego katalogu.
size_t __size - rozmiar bufora na łańcuch znaków przekazany w argumencie __buf.
Zwracana wartość:
char * - łańcuch znaków (wskaźnik do łańcucha znaków) przekazany w argumencie __buf (w przypadku gdy nie jest on
NULL
) zawierający ścieżkę do bieżącego katalogu.#top getdents¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
getdents()
nie znajduje się w żadnym pliku nagłówkowym, gdyż biblioteka systemowa nie udostępnia żadnego funkcji obudowującej to wywołanie. Niezbędne jest tutaj wywołanie tej funkcji systemowej za pomocą syscall().Deklaracja funkcji
getdents()
jest następująca:int getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count);
Powiązane:
alphasort(), getdents(), getdirentries(), glob(), globfree(), scandir(), versionsort(),
Opis:
Funkcja getdents() odczytuje elementy z katalogu określonego deskryptorem przekazanym w argumencie fd do bufora przekazanego w argumencie dirp. Ilość odczytanych bajtów jest nie większa niż wartość określona w argumencie count. Funkcja getdents() zwraca ilość odczytanych danych lub zero po odczytaniu wszystkich elementów z katalogu. W przypadku błędu funkcja zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
unsigned int fd - deskryptor wskazujący na katalog z którego odczytane zostaną elementy.
struct linux_dirent *dirp - bufor do którego zostaną odczytane elementy z katalogu wskazywanego deskryptorem fd.
Zwracana wartość:
int - ilość odczytanych danych lub zero po odczytaniu wszystkich elementów z katalogu lub -1 w przypadku wystąpienia błędu.
Argumenty:
unsigned int fd - deskryptor wskazujący na katalog z którego odczytane zostaną elementy.
struct linux_dirent *dirp - bufor do którego zostaną odczytane elementy z katalogu wskazywanego deskryptorem fd.
Struktura struct linux_dirent zawiera następujące pola:
Currently, only some file systems (among them: Btrfs, ext2, etx3, and ext4) have full support for returning the file type in d_type.
All applications must properly handle a return of DT_UNKNOWN.
unsigned int count - wielkość bufora określonego argumentem dirp do którego zostaną odczytane dane, lecz nie więcej niż count bajtów.- d_ino zawiera numer inode.
- d_off zawiera informacje o pozycji przesunięciu pozycji bieżacego elementu katalogu względem pozycji następnego elementu katalogu linux_dirent.
- d_reclen wielkość elementu katalogu opisanego strukturą linux_dirent.
- d_name nazwa elementu katalogu będąca łańcuchem znaków (wskaźnikiem do łańcucha znaków) zakończona bajtem 0x00 (NULL).
- d_type bajt na końcu struktury określający określający typ elementu katalogu. Zawiera jedną z następujących wartości (zdefiniowanych w pliku nagłówkowym
dirent.h
):- DT_BLK element jest urządzeniem blokowym.
- DT_CHR element jest urządzeniem znakowym.
- DT_DIR element jest katalogiem.
- DT_FIFO element jest nazwanym potokime (FIFO).
- DT_LNK element jest dowiązaniem symbolicznym (linkiem symbolicznym).
- DT_REG element jest regularnym plikiem (zwykłym plikiem).
- DT_SOCK element jest gniazdem Unix.
- DT_UNKNOWN element jest nieznanego typu.
Currently, only some file systems (among them: Btrfs, ext2, etx3, and ext4) have full support for returning the file type in d_type.
All applications must properly handle a return of DT_UNKNOWN.
Zwracana wartość:
int - ilość odczytanych danych lub zero po odczytaniu wszystkich elementów z katalogu lub -1 w przypadku wystąpienia błędu.
Example:
zawartość pliku
getdents.c
SELECT ALL
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/getdentsprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/getdents </path/to/directory> Examples: /home/local/code/ansiccode/sysdir/getdents /home/local/code/ansiccode/sysdir
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/getdents /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
#top getdirentries¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
getdirentries()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
getdirentries()
jest następująca:/* Read directory entries from FD into BUF, reading at most NBYTES. Reading starts at offset *BASEP, and *BASEP is updated with the new position after reading. Returns the number of bytes read; zero when at end of directory; or -1 for errors. */ # ifndef __USE_FILE_OFFSET64 extern __ssize_t getdirentries (int __fd, char *__restrict __buf, size_t __nbytes, __off_t *__restrict __basep) __THROW __nonnull ((2, 4)); # else # ifdef __REDIRECT extern __ssize_t __REDIRECT_NTH (getdirentries, (int __fd, char *__restrict __buf, size_t __nbytes, __off64_t *__restrict __basep), getdirentries64) __nonnull ((2, 4)); # else # define getdirentries getdirentries64 # endif # endif
Powiązane:
alphasort(), getdents(), getdirentries(), glob(), globfree(), scandir(), versionsort(),
Opis:
Funkcja getdirentries() odczytuje elementy z katalogu określonego deskryptorem przekazanym w argumencie __fd do bufora przekazanego w argumencie __buf. Ilość odczytanych bajtów jest nie większa niż wartość określona w argumencie __nbytes. Odczyt danych rozpoczyna się od indeksu przekazanego w argumencie __basep. Funkcja getdirentries() zwraca ilość odczytanych danych lub zero po odczytaniu wszystkich elementów z katalogu. W przypadku błędu funkcja zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
int __fd - deskryptor wskazujący na katalog z którego odczytane zostaną elementy.
char *__restrict __buf - bufor do którego zostaną odczytane elementy z katalogu wskazywanego deskryptorem __fd.
size_t __nbytes - wielkość bufora określonego argumentem __buf do którego zostaną odczytane dane, lecz nie więcej niż __nbytes bajtów.
__off_t *__restrict __basep - indeks od którego rozpocznie się odczyt elementów z katalogu (w przypadku gdy wszystkie elementy z katalogu nie zmieściły się do bufora, pozostałe elementy zostaną odczytane przy kolejnych wywołaniach funkcji).
Zwracana wartość:
__ssize_t - ilość odczytanych danych lub zero po odczytaniu wszystkich elementów z katalogu lub -1 w przypadku wystąpienia błędu.
Argumenty:
int __fd - deskryptor wskazujący na katalog z którego odczytane zostaną elementy.
char *__restrict __buf - bufor do którego zostaną odczytane elementy z katalogu wskazywanego deskryptorem __fd.
size_t __nbytes - wielkość bufora określonego argumentem __buf do którego zostaną odczytane dane, lecz nie więcej niż __nbytes bajtów.
__off_t *__restrict __basep - indeks od którego rozpocznie się odczyt elementów z katalogu (w przypadku gdy wszystkie elementy z katalogu nie zmieściły się do bufora, pozostałe elementy zostaną odczytane przy kolejnych wywołaniach funkcji).
Zwracana wartość:
__ssize_t - ilość odczytanych danych lub zero po odczytaniu wszystkich elementów z katalogu lub -1 w przypadku wystąpienia błędu.
Example:
zawartość pliku
getdirentries.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(), getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include <fcntl.h> /* for io.h, O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND, */ #else #include <fcntl.h> /* for O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND, F_GETFL, F_SETFL, O_NONBLOCK, O_SYNC, FASYNC, O_DIRECT, O_LARGEFILE, O_DIRECTORY, O_NOFOLLOW, O_NOATIME, O_NDELAY, */ /* for LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN, LOCK_MAND, LOCK_READ, LOCK_WRITE, LOCK_RW, fcntl(), open(), creat(), */ #endif #define BUFFSIZE 16384 int main(int argc, char **argv) { char *self; int fprd; #if defined(HAVE_GETDIRENTRIES) struct dirent *dirrow; #endif int result; int irow; #if defined(HAVE_GETDIRENTRIES) char buffdata[BUFFSIZE]; int rcount; long int pointer; #endif self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); printf("Examples:\n"); printf(" %s /home/local/code/ansiccode/sysdir\n", argv[0]); return 0; } fprd=open(argv[1], O_RDONLY, 0644); if (fprd>=0) { printf("%s: fprd=open(argv[1]=%s, O_RDONLY=%d, 0644); fprd=%d if (fprd>=0): Successful open().\n", self, argv[1], O_RDONLY, fprd); irow=0; #if defined(HAVE_GETDIRENTRIES) while ( (rcount=getdirentries(fprd,buffdata,BUFFSIZE,&pointer))>0) { for (dirrow=(struct dirent *)buffdata; (char *)dirrow<&buffdata[rcount]; dirrow=(struct dirent *)((int)dirrow+(dirrow->d_reclen)) ) { printf("%s: dirrow-buffdata=%ld\t", self, (long int)((char *)dirrow-buffdata)); #if defined(HAVE_DIRENT_TYPEOFF) printf("[%02d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld\n", irow++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino); #else printf("[%02d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld\n", irow++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino); #endif } printf("%s: pointer=%ld\n", self, pointer); } #else /* getdirentries() is not available on this OS platform !!! */ printf("%s: getdirentries() is not available on this OS platform !!!\n", self); #endif /* HAVE_GETDIRENTRIES */ result=close(fprd); if (result>=0) printf("%s: result=close(fprd=%d); result=%d if (result>=0): Successful close().\n", self, fprd, result); else printf("%s: result=close(fprd=%d); result=%d if (result>=0): else: Unable to close(), Reason=%d:%s\n", self, fprd, result, errno, strerror(errno)); } else { printf("%s: fprd=open(argv[1]=%s, O_RDONLY=%d, 0644); fprd=%d if (fprd>=0): else: Unable to open(), Reason: %d:%s\n", self, argv[1], O_RDONLY, fprd, errno, strerror(errno)); } return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/getdirentriesprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/getdirentries </path/to/directory> Examples: /home/local/code/ansiccode/sysdir/getdirentries /home/local/code/ansiccode/sysdir
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/getdirentries /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
getdirentries: fprd=open(argv[1]=/home/local/code/ansiccode/sysdir, O_RDONLY=0, 0644); fprd=3 if (fprd>=0): Successful open(). getdirentries: dirrow-buffdata=0 [00] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 getdirentries: dirrow-buffdata=20 [01] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 getdirentries: dirrow-buffdata=40 [02] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=130721592 dirrow->d_ino=1410318 getdirentries: dirrow-buffdata=64 [03] dirrow->d_name=versionsort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1411053 getdirentries: dirrow-buffdata=88 [04] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 getdirentries: dirrow-buffdata=112 [05] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=326292342 dirrow->d_ino=1410387 getdirentries: dirrow-buffdata=136 [06] dirrow->d_name=glob.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=340175332 dirrow->d_ino=1411054 getdirentries: dirrow-buffdata=156 [07] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=361703713 dirrow->d_ino=1410445 getdirentries: dirrow-buffdata=176 [08] dirrow->d_name=alphasort.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=427406474 dirrow->d_ino=1411008 getdirentries: dirrow-buffdata=200 [09] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 getdirentries: dirrow-buffdata=220 [10] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 getdirentries: dirrow-buffdata=240 [11] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 getdirentries: dirrow-buffdata=260 [12] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410658 getdirentries: dirrow-buffdata=284 [13] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 getdirentries: dirrow-buffdata=304 [14] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=687030437 dirrow->d_ino=1410448 getdirentries: dirrow-buffdata=324 [15] dirrow->d_name=dirfd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=714692598 dirrow->d_ino=1411007 getdirentries: dirrow-buffdata=344 [16] dirrow->d_name=fdopendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=718026284 dirrow->d_ino=1410990 getdirentries: dirrow-buffdata=368 [17] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 getdirentries: dirrow-buffdata=388 [18] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 getdirentries: dirrow-buffdata=412 [19] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 getdirentries: dirrow-buffdata=436 [20] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 getdirentries: dirrow-buffdata=456 [21] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 getdirentries: dirrow-buffdata=480 [22] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1336351603 dirrow->d_ino=1410440 getdirentries: dirrow-buffdata=500 [23] dirrow->d_name=glob dirrow->d_type=0x08 dirrow->d_reclen=16 dirrow->d_off=1345128052 dirrow->d_ino=1411025 getdirentries: dirrow-buffdata=516 [24] dirrow->d_name=.. dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=1378150461 dirrow->d_ino=1410182 getdirentries: dirrow-buffdata=532 [25] dirrow->d_name=glob-fnmatch dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1383606058 dirrow->d_ino=1411050 getdirentries: dirrow-buffdata=556 [26] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1423750639 dirrow->d_ino=1410392 getdirentries: dirrow-buffdata=580 [27] dirrow->d_name=fdopendir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410972 getdirentries: dirrow-buffdata=604 [28] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1558810147 dirrow->d_ino=1409388 getdirentries: dirrow-buffdata=628 [29] dirrow->d_name=getdirentries.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1603650525 dirrow->d_ino=1410377 getdirentries: dirrow-buffdata=656 [30] dirrow->d_name=glob-fnmatch.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1638081534 dirrow->d_ino=1411180 getdirentries: dirrow-buffdata=684 [31] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1707577288 dirrow->d_ino=1410521 getdirentries: dirrow-buffdata=704 [32] dirrow->d_name=mkdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1709357308 dirrow->d_ino=1411037 getdirentries: dirrow-buffdata=724 [33] dirrow->d_name=mkdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1771880146 dirrow->d_ino=1411061 getdirentries: dirrow-buffdata=744 [34] dirrow->d_name=dirfd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410758 getdirentries: dirrow-buffdata=764 [35] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 getdirentries: dirrow-buffdata=784 [36] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1853408271 dirrow->d_ino=1409845 getdirentries: dirrow-buffdata=812 [37] dirrow->d_name=alphasort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1903302723 dirrow->d_ino=1410274 getdirentries: dirrow-buffdata=836 [38] dirrow->d_name=rmdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1934495362 dirrow->d_ino=1411048 getdirentries: dirrow-buffdata=856 [39] dirrow->d_name=getdirentries dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1964717140 dirrow->d_ino=1410996 getdirentries: dirrow-buffdata=884 [40] dirrow->d_name=versionsort.c dirrow->d_type=0x0A dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1411051 getdirentries: dirrow-buffdata=912 [41] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2007201532 dirrow->d_ino=1410530 getdirentries: dirrow-buffdata=940 [42] dirrow->d_name=rmdir.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=2010445905 dirrow->d_ino=1411023 getdirentries: dirrow-buffdata=960 [43] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 getdirentries: dirrow-buffdata=984 [44] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 getdirentries: dirrow-buffdata=1000 [45] dirrow->d_name=. dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2115597079 dirrow->d_ino=1410666 getdirentries: dirrow-buffdata=1016 [46] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410461 getdirentries: pointer=0 getdirentries: result=close(fprd=3); result=0 if (result>=0): Successful close().
#top glob¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
glob()
znajduje się w pliku nagłówkowym glob.h
.Deklaracja funkcji
glob()
jest następująca:/* Do glob searching for PATTERN, placing results in PGLOB. The bits defined above may be set in FLAGS. If a directory cannot be opened or read and ERRFUNC is not nil, it is called with the pathname that caused the error, and the `errno' value from the failing call; if it returns non-zero `glob' returns GLOB_ABEND; if it returns zero, the error is ignored. If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. Otherwise, `glob' returns zero. */ #if !defined __USE_FILE_OFFSET64 || __GNUC__ < 2 extern int glob (__const char *__restrict __pattern, int __flags, int (*__errfunc) (__const char *, int), glob_t *__restrict __pglob) __THROW;
Powiązane:
alphasort(), getdents(), getdirentries(), glob(), globfree(), scandir(), versionsort(),
Opis:
Funkcja glob() przeszukuje podaną jako argument __pattern ścieżkę zgodnie z wyrażeniem regularnym i zwraca jako wynik elementy pasujące do wyrażenia regularnego zawartego w argumencie.
Argumenty:
const char *__restrict __pattern - wyrażenie regularne określające ścieżkę do poszukiwanych elementów.
int __flags - flagi modyfikujące zachowanie funkcji oraz zwracane wyniki, może zawierać sumę logiczną następujących wartości:
glob_t *__restrict __pglob - wskaźnik do struktury zawierającej wynik dopasowania do podanego w argumencie __pattern wyrażenia regularnego.
Zwracana wartość:
int - W przypadku sukcesu funkcja zwraca w elemencie gl_pathv struktury glob_t listę dopasowanych do wyrażenia elementów struktury katalogów.
Argumenty:
const char *__restrict __pattern - wyrażenie regularne określające ścieżkę do poszukiwanych elementów.
int __flags - flagi modyfikujące zachowanie funkcji oraz zwracane wyniki, może zawierać sumę logiczną następujących wartości:
The parameter flags is made up of bitwise OR of zero or more the following symbolic constants, which modify the of behaviour of glob():
GLOB_ERR which means to return upon read error (because a directory does not have read permission, for example),
GLOB_MARK which means to append a slash to each path which corresponds to a directory,
GLOB_NOSORT which means don't sort the returned pathnames (they are by default),
GLOB_DOOFFS which means that pglob->gl_offs slots will be reserved at the beginning of the list of strings in pglob->pathv,
GLOB_NOCHECK which means that, if no pattern matches, to return the original pattern,
GLOB_APPEND which means to append to the results of a previous call. Do not set this flag on the first invocation of glob().
GLOB_NOESCAPE which means that meta characters cannot be quoted by backslashes.
The flags may also include some of the following, which are GNU extensions and not defined by POSIX.2:
GLOB_PERIOD which means that a leading period can be matched by meta characters,
GLOB_ALTDIRFUNC which means that alternative functions pglob->gl_closedir, pglob->gl_readdir, pglob->gl_opendir, pglob->gl_lstat, and pglob->gl_stat are used for file system access instead of the normal library functions,
GLOB_BRACE which means that csh(1) style brace expressions {a,b} are expanded,
GLOB_NOMAGIC which means that the pattern is returned if it contains no metacharacters,
GLOB_TILDE which means that tilde expansion is carried out, and
GLOB_ONLYDIR which means that only directories are matched.
int (*__errfunc) (__const char *, int) - wskaźnik do funkcji obsługi błedów, które mogą wystąpić podczas przeszukiwania ścieżki.GLOB_ERR which means to return upon read error (because a directory does not have read permission, for example),
GLOB_MARK which means to append a slash to each path which corresponds to a directory,
GLOB_NOSORT which means don't sort the returned pathnames (they are by default),
GLOB_DOOFFS which means that pglob->gl_offs slots will be reserved at the beginning of the list of strings in pglob->pathv,
GLOB_NOCHECK which means that, if no pattern matches, to return the original pattern,
GLOB_APPEND which means to append to the results of a previous call. Do not set this flag on the first invocation of glob().
GLOB_NOESCAPE which means that meta characters cannot be quoted by backslashes.
The flags may also include some of the following, which are GNU extensions and not defined by POSIX.2:
GLOB_PERIOD which means that a leading period can be matched by meta characters,
GLOB_ALTDIRFUNC which means that alternative functions pglob->gl_closedir, pglob->gl_readdir, pglob->gl_opendir, pglob->gl_lstat, and pglob->gl_stat are used for file system access instead of the normal library functions,
GLOB_BRACE which means that csh(1) style brace expressions {a,b} are expanded,
GLOB_NOMAGIC which means that the pattern is returned if it contains no metacharacters,
GLOB_TILDE which means that tilde expansion is carried out, and
GLOB_ONLYDIR which means that only directories are matched.
glob_t *__restrict __pglob - wskaźnik do struktury zawierającej wynik dopasowania do podanego w argumencie __pattern wyrażenia regularnego.
Zwracana wartość:
int - W przypadku sukcesu funkcja zwraca w elemencie gl_pathv struktury glob_t listę dopasowanych do wyrażenia elementów struktury katalogów.
Example:
zawartość pliku
glob.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #if defined(HAVE_GLOB) #include <glob.h> /* for GLOB_ERR, GLOB_MARK, GLOB_NOSORT, GLOB_DOOFFS, GLOB_NOCHECK, GLOB_APPEND, GLOB_NOESCAPE, GLOB_PERIOD, glob_t, glob(), globfree(), */ #endif int main(int argc, char **argv) { char *self; #if defined(HAVE_GLOB) glob_t globbuf; size_t cnt; #endif int result; int irow; char **p; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); printf("Examples:\n"); printf(" %s \"/home/local/code/ansiccode/sysdir/*.c\"\n", argv[0]); printf(" %s \"/home/local/code/ansiccode/sysdir/*.cpp\"\n", argv[0]); printf(" %s \"/home/local/code/ansiccode/sysdir/*.h\"\n", argv[0]); printf(" %s \"/home/local/code/ansiccode/sysdir/Makefile*\"\n", argv[0]); return 0; } printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf):\n", self, argv[1]); #if defined(HAVE_GLOB) globbuf.gl_offs=0; result=glob(argv[1], GLOB_DOOFFS, /*int (*__errfunc) (__const char *, int)*/NULL, &globbuf); if (globbuf.gl_pathc && globbuf.gl_pathv) { printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf): result=%d if (globbuf.gl_pathc && globbuf.gl_pathv): Successful glob().\n", self, argv[1], result); printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf): result=%d globbuf.gl_offs=%d globbuf.gl_pathc=%d\n", self, argv[1], result, globbuf.gl_offs, globbuf.gl_pathc); for (p=globbuf.gl_pathv,cnt=globbuf.gl_pathc; cnt; p++,cnt--) { printf("%s: result=glob(): globbuf.gl_offs=%d globbuf.gl_pathc=%d p=%s cnt=%d\n", self, globbuf.gl_offs, globbuf.gl_pathc, *p, cnt); } for (irow=0;irow<(int)globbuf.gl_offs;irow++) printf("%s: globbuf.gl_offs=%d globbuf.gl_pathv[%d]=%s\n", self, globbuf.gl_offs, irow, globbuf.gl_pathv[irow]); globfree(&globbuf); } else { if (result==GLOB_NOSPACE) printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf): result=%d if (globbuf.gl_pathc && globbuf.gl_pathv): else: Unable to glob(), Reason: if (result==GLOB_NOSPACE): GLOB_NOSPACE 1 /* Ran out of memory. */\n", self, argv[1], result); else if (result==GLOB_ABORTED) printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf): result=%d if (globbuf.gl_pathc && globbuf.gl_pathv): else: Unable to glob(), Reason: if (result==GLOB_ABORTED): GLOB_ABORTED 2 /* Read error. */\n", self, argv[1], result); else if (result==GLOB_NOMATCH) printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf): result=%d if (globbuf.gl_pathc && globbuf.gl_pathv): else: Unable to glob(), Reason: if (result==GLOB_NOMATCH): GLOB_NOMATCH 3 /* No matches found. */\n", self, argv[1], result); else if (result==GLOB_NOSYS) printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf): result=%d if (globbuf.gl_pathc && globbuf.gl_pathv): else: Unable to glob(), Reason: if (result==GLOB_NOSYS): GLOB_NOSYS 4 /* Not implemented. */\n", self, argv[1], result); else printf("%s: result=glob(argv[1]=%s, GLOB_DOOFFS, NULL, &globbuf): result=%d if (globbuf.gl_pathc && globbuf.gl_pathv): else: Unable to glob(), Reason: else: Unknown error.\n", self, argv[1], result); } #else /* glob() is not available on this OS platform !!! */ printf("%s: glob() is not available on this OS platform !!!\n", self); result=-1; /* globfree() is not available on this OS platform !!! */ printf("%s: globfree() is not available on this OS platform !!!\n", self); #endif return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/globprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/glob </path/to/directory> Examples: /home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/*.c" /home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/*.cpp" /home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/*.h" /home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/Makefile*"
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/*.c" /home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/*.cpp" /home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/*.h" /home/local/code/ansiccode/sysdir/glob "/home/local/code/ansiccode/sysdir/Makefile*"rezultat będzie zależny od podanych argumentów wywołania programu:
glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/*.c, GLOB_DOOFFS, NULL, &globbuf): glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/*.c, GLOB_DOOFFS, NULL, &globbuf): result=0 if (globbuf.gl_pathc && globbuf.gl_pathv): Successful glob(). glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/*.c, GLOB_DOOFFS, NULL, &globbuf): result=0 globbuf.gl_offs=0 globbuf.gl_pathc=19 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/alphasort.c cnt=19 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/chdir.c cnt=18 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/chroot.c cnt=17 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/closedir.c cnt=16 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/dirfd.c cnt=15 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/fdopendir.c cnt=14 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/getcwd.c cnt=13 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/getdirentries.c cnt=12 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/glob-fnmatch.c cnt=11 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/glob.c cnt=10 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/mkdir.c cnt=9 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/opendir.c cnt=8 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/readdir.c cnt=7 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/rewinddir.c cnt=6 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/rmdir.c cnt=5 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/scandir.c cnt=4 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/seekdir.c cnt=3 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/telldir.c cnt=2 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=19 p=/home/local/code/ansiccode/sysdir/versionsort.c cnt=1 glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/*.cpp, GLOB_DOOFFS, NULL, &globbuf): glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/*.cpp, GLOB_DOOFFS, NULL, &globbuf): result=3 if (globbuf.gl_pathc && globbuf.gl_pathv): else: Unable to glob(), Reason: if (result==GLOB_NOMATCH): GLOB_NOMATCH 3 /* No matches found. */ glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/*.h, GLOB_DOOFFS, NULL, &globbuf): glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/*.h, GLOB_DOOFFS, NULL, &globbuf): result=3 if (globbuf.gl_pathc && globbuf.gl_pathv): else: Unable to glob(), Reason: if (result==GLOB_NOMATCH): GLOB_NOMATCH 3 /* No matches found. */ glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/Makefile*, GLOB_DOOFFS, NULL, &globbuf): glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/Makefile*, GLOB_DOOFFS, NULL, &globbuf): result=0 if (globbuf.gl_pathc && globbuf.gl_pathv): Successful glob(). glob: result=glob(argv[1]=/home/local/code/ansiccode/sysdir/Makefile*, GLOB_DOOFFS, NULL, &globbuf): result=0 globbuf.gl_offs=0 globbuf.gl_pathc=6 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=6 p=/home/local/code/ansiccode/sysdir/Makefile cnt=6 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=6 p=/home/local/code/ansiccode/sysdir/Makefile.beos cnt=5 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=6 p=/home/local/code/ansiccode/sysdir/Makefile.fbsd cnt=4 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=6 p=/home/local/code/ansiccode/sysdir/Makefile.obsd cnt=3 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=6 p=/home/local/code/ansiccode/sysdir/Makefile.sol cnt=2 glob: result=glob(): globbuf.gl_offs=0 globbuf.gl_pathc=6 p=/home/local/code/ansiccode/sysdir/Makefile.win cnt=1
Example:
zawartość pliku
glob-fnmatch.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ #include <fnmatch.h> /* for FNM_PATHNAME, FNM_NOESCAPE, FNM_PERIOD, FNM_LEADING_DIR, FNM_CASEFOLD, FNM_EXTMATCH, FNM_NOMATCH fnmatch(), */ int main(int argc, char **argv) { char *self; DIR *dirfd; struct dirent *dirrow; int result; int irow; char workdir[1024]; char basefile[1024]; char *sp1; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory/pattern>\n", argv[0]); printf("Examples:\n"); printf(" %s \"/home/local/code/ansiccode/sysdir/*.c\"\n", argv[0]); printf(" %s \"/home/local/code/ansiccode/sysdir/*.cpp\"\n", argv[0]); printf(" %s \"/home/local/code/ansiccode/sysdir/*.h\"\n", argv[0]); printf(" %s \"/home/local/code/ansiccode/sysdir/Makefile*\"\n", argv[0]); return 0; } memset(workdir, 0x00, sizeof(workdir)); strncpy(workdir, argv[1], sizeof(workdir)); sp1=strrchr(workdir, '/'); if (sp1!=NULL) *sp1=0x00; memset(basefile, 0x00, sizeof(basefile)); strncpy(basefile, argv[1], sizeof(basefile)); sp1=strrchr(basefile, '/'); if (sp1!=NULL) strncpy(basefile, sp1+1, sizeof(basefile)); dirfd=opendir(workdir); if (dirfd != NULL) { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): Successful opendir().\n", self, workdir, (void*)dirfd); irow=0; printf("%s: while ((dirrow=readdir(dirfd)) != NULL):\n", self); while ((dirrow=readdir(dirfd)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; if (fnmatch(basefile,dirrow->d_name,FNM_PATHNAME)==0) { #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: if (fnmatch(basefile=%s,dirrow->d_name=%s,FNM_PATHNAME|FNM_NOCASE)==0): [%02d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, basefile, dirrow->d_name, irow++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd)); #else printf("%s: if (fnmatch(basefile=%s,dirrow->d_name=%s,FNM_PATHNAME|FNM_NOCASE)==0): [%02d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, basefile, dirrow->d_name, irow++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd)); #endif } } result=closedir(dirfd); if (result>=0) printf("%s: result=closedir(dirfd): result=%d if (result>=0): Successful closedir().\n", self, result); else printf("%s: result=closedir(dirfd): result=%d if (result>=0): else: Unable to closedir(), Reason: %d:%s\n", self, result, errno, strerror(errno)); } else { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): else: Unable to opendir(), Reason: %d:%s\n", self, argv[1], (void*)dirfd, errno, strerror(errno)); } return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/glob-fnmatchprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/glob-fnmatch </path/to/directory/pattern> Examples: /home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/*.c" /home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/*.cpp" /home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/*.h" /home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/Makefile*"
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/*.c" /home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/*.cpp" /home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/*.h" /home/local/code/ansiccode/sysdir/glob-fnmatch "/home/local/code/ansiccode/sysdir/Makefile*"rezultat będzie zależny od podanych argumentów wywołania programu:
glob-fnmatch: dirfd=opendir(workdir=/home/local/code/ansiccode/sysdir): dirfd=0x89b4008 if (dirfd != NULL): Successful opendir(). glob-fnmatch: while ((dirrow=readdir(dirfd)) != NULL): glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=opendir.c,FNM_PATHNAME|FNM_NOCASE)==0): [00] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 telldir(dirfd)=258066785 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=readdir.c,FNM_PATHNAME|FNM_NOCASE)==0): [01] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=326292342 dirrow->d_ino=1410387 telldir(dirfd)=326292342 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=glob.c,FNM_PATHNAME|FNM_NOCASE)==0): [02] dirrow->d_name=glob.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=340175332 dirrow->d_ino=1411054 telldir(dirfd)=340175332 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=alphasort.c,FNM_PATHNAME|FNM_NOCASE)==0): [03] dirrow->d_name=alphasort.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=427406474 dirrow->d_ino=1411008 telldir(dirfd)=427406474 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=getcwd.c,FNM_PATHNAME|FNM_NOCASE)==0): [04] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 telldir(dirfd)=625605754 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=chroot.c,FNM_PATHNAME|FNM_NOCASE)==0): [05] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 telldir(dirfd)=661949438 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=chdir.c,FNM_PATHNAME|FNM_NOCASE)==0): [06] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=687030437 dirrow->d_ino=1410448 telldir(dirfd)=687030437 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=dirfd.c,FNM_PATHNAME|FNM_NOCASE)==0): [07] dirrow->d_name=dirfd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=714692598 dirrow->d_ino=1411007 telldir(dirfd)=714692598 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=fdopendir.c,FNM_PATHNAME|FNM_NOCASE)==0): [08] dirrow->d_name=fdopendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=718026284 dirrow->d_ino=1410990 telldir(dirfd)=718026284 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=seekdir.c,FNM_PATHNAME|FNM_NOCASE)==0): [09] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 telldir(dirfd)=866081774 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=closedir.c,FNM_PATHNAME|FNM_NOCASE)==0): [10] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 telldir(dirfd)=1166638244 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=scandir.c,FNM_PATHNAME|FNM_NOCASE)==0): [11] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1423750639 dirrow->d_ino=1410392 telldir(dirfd)=1423750639 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=rewinddir.c,FNM_PATHNAME|FNM_NOCASE)==0): [12] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1558810147 dirrow->d_ino=1409388 telldir(dirfd)=1558810147 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=getdirentries.c,FNM_PATHNAME|FNM_NOCASE)==0): [13] dirrow->d_name=getdirentries.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1603650525 dirrow->d_ino=1410377 telldir(dirfd)=1603650525 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=glob-fnmatch.c,FNM_PATHNAME|FNM_NOCASE)==0): [14] dirrow->d_name=glob-fnmatch.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1638081534 dirrow->d_ino=1411180 telldir(dirfd)=1638081534 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=mkdir.c,FNM_PATHNAME|FNM_NOCASE)==0): [15] dirrow->d_name=mkdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1771880146 dirrow->d_ino=1411061 telldir(dirfd)=1771880146 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=versionsort.c,FNM_PATHNAME|FNM_NOCASE)==0): [16] dirrow->d_name=versionsort.c dirrow->d_type=0x0A dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1411051 telldir(dirfd)=1967637597 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=rmdir.c,FNM_PATHNAME|FNM_NOCASE)==0): [17] dirrow->d_name=rmdir.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=2010445905 dirrow->d_ino=1411023 telldir(dirfd)=2010445905 glob-fnmatch: if (fnmatch(basefile=*.c,dirrow->d_name=telldir.c,FNM_PATHNAME|FNM_NOCASE)==0): [18] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 telldir(dirfd)=2069417274 glob-fnmatch: result=closedir(dirfd): result=0 if (result>=0): Successful closedir(). glob-fnmatch: dirfd=opendir(workdir=/home/local/code/ansiccode/sysdir): dirfd=0x8116008 if (dirfd != NULL): Successful opendir(). glob-fnmatch: while ((dirrow=readdir(dirfd)) != NULL): glob-fnmatch: result=closedir(dirfd): result=0 if (result>=0): Successful closedir(). glob-fnmatch: dirfd=opendir(workdir=/home/local/code/ansiccode/sysdir): dirfd=0x940b008 if (dirfd != NULL): Successful opendir(). glob-fnmatch: while ((dirrow=readdir(dirfd)) != NULL): glob-fnmatch: result=closedir(dirfd): result=0 if (result>=0): Successful closedir(). glob-fnmatch: dirfd=opendir(workdir=/home/local/code/ansiccode/sysdir): dirfd=0x9d35008 if (dirfd != NULL): Successful opendir(). glob-fnmatch: while ((dirrow=readdir(dirfd)) != NULL): glob-fnmatch: if (fnmatch(basefile=Makefile*,dirrow->d_name=Makefile.sol,FNM_PATHNAME|FNM_NOCASE)==0): [00] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=130721592 dirrow->d_ino=1410318 telldir(dirfd)=130721592 glob-fnmatch: if (fnmatch(basefile=Makefile*,dirrow->d_name=Makefile.win,FNM_PATHNAME|FNM_NOCASE)==0): [01] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410658 telldir(dirfd)=679195114 glob-fnmatch: if (fnmatch(basefile=Makefile*,dirrow->d_name=Makefile,FNM_PATHNAME|FNM_NOCASE)==0): [02] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1707577288 dirrow->d_ino=1410521 telldir(dirfd)=1707577288 glob-fnmatch: if (fnmatch(basefile=Makefile*,dirrow->d_name=Makefile.fbsd,FNM_PATHNAME|FNM_NOCASE)==0): [03] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1853408271 dirrow->d_ino=1409845 telldir(dirfd)=1853408271 glob-fnmatch: if (fnmatch(basefile=Makefile*,dirrow->d_name=Makefile.obsd,FNM_PATHNAME|FNM_NOCASE)==0): [04] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2007201532 dirrow->d_ino=1410530 telldir(dirfd)=2007201532 glob-fnmatch: if (fnmatch(basefile=Makefile*,dirrow->d_name=Makefile.beos,FNM_PATHNAME|FNM_NOCASE)==0): [05] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410461 telldir(dirfd)=2147483647 glob-fnmatch: result=closedir(dirfd): result=0 if (result>=0): Successful closedir().
#top globfree¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
globfree()
znajduje się w pliku nagłówkowym glob.h
.Deklaracja funkcji
globfree()
jest następująca:/* Free storage allocated in PGLOB by a previous * `glob()' call. *: extern void globfree (glob_t *__pglob) __THROW;
Powiązane:
alphasort(), getdents(), getdirentries(), glob(), globfree(), scandir(), versionsort(),
Opis:
Funkcja globfree() wykonuje operacje odwrotną do funkcji glob(), która alokuje pamięć na dane zwracanego wyniku działania funkcji, czyli zwalnia zaalokowane zasoby (pełni funkcję sprzątającą).
Argumenty:
glob_t *__pglob - wskaźnik do struktury zawierającej zaalokowany przez funkcję glob() wynik, który ma zostać zwolniony.
Zwracana wartość:
Funkcja nie zwraca żadnej wartości.
Argumenty:
glob_t *__pglob - wskaźnik do struktury zawierającej zaalokowany przez funkcję glob() wynik, który ma zostać zwolniony.
Zwracana wartość:
Funkcja nie zwraca żadnej wartości.
#top mkdir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
mkdir()
znajduje się w pliku nagłówkowym sys/stat.h
.Deklaracja funkcji
mkdir()
jest następująca:/* Create a new directory named PATH, with permission bits MODE. */ extern int mkdir (__const char *__path, __mode_t __mode) __THROW __nonnull ((1));
Powiązane:
mkdir(), mkdirat(), rmdir(),
Opis:
Funkcja mkdir() tworzy katalog o nazwie podanej w argumencie __path oraz ustawia uprawnienia nowo utworzonego katalogu na podane w argumencie __mode. W przypadku sukcesu wykonania operacji funkcja zwraca wartość 0, w przeciwnym przypadku funkcja zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający nazwę tworzonego katalogu.
__mode_t __mode - uprawnienia utworzonego katalogu.
Zwracana wartość:
int - status wynonania operacji: 0 w przypadku sukcesu, -1 w przypadku wystąpienia błędu.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający nazwę tworzonego katalogu.
__mode_t __mode - uprawnienia utworzonego katalogu.
Zwracana wartość:
int - status wynonania operacji: 0 w przypadku sukcesu, -1 w przypadku wystąpienia błędu.
Example:
zawartość pliku
mkdir.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include <io.h> /* for FILENAME_MAX, F_OK, X_OK, W_OK, R_OK, chdir(), getcwd(), mkdir(), mktemp(), rmdir(), chmod(), access(), chsize(), close(), creat(), */ /* dup(), dup2(), eof(), filelength(), isatty(), lseek(), open(), read(), tell(), umask(), unlink(), write(), */ #else #include <sys/stat.h> /* for dev_t, gid_t, ino_t, mode_t, off_t, uid_t, blkcnt_t, blksize_t, struct stat, stat(), fstat(), lstat(), chmod(), lchmod(), umask(), getumask(), mkdir(), mknod(), mkfifo(), */ #endif int main(int argc, char **argv) { char *self; int result; #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) int varumask; #else __mode_t varumask; #endif self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<3) { printf("Usage: %s </path/to/create-directory> </path/to/remove-directory>\n", argv[0]); printf("Examples:\n"); printf(" %s /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir2\n", argv[0]); printf(" %s /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir2\n", argv[0]); printf(" %s /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir1\n", argv[0]); return 0; } varumask=umask(0777); umask(varumask); varumask=0777-varumask; printf("%s: result=mkdir(argv[1]=%s, varumask=%o):\n", self, argv[1], (int)varumask); result=mkdir(argv[1], varumask); if (result>=0) printf("%s: result=mkdir(argv[1]=%s, varumask=%o): result=%d if (result>=0): Successful mkdir().\n", self, argv[1], (int)varumask, result); else printf("%s: result=mkdir(argv[1]=%s, varumask=%o): result=%d if (result>=0): else: Unable to mkdir(), Reason: %d:%s\n", self, argv[1], (int)varumask, result, errno, strerror(errno)); printf("%s: result=rmdir(argv[2]=%s):\n", self, argv[2]); result=rmdir(argv[2]); if (result>=0) printf("%s: result=rmdir(argv[2]=%s): result=%d if (result>=0): Successful rmdir().\n", self, argv[2], result); else printf("%s: result=rmdir(argv[2]=%s): result=%d if (result>=0): else: Unable to rmdir(), Reason: %d:%s\n", self, argv[2], result, errno, strerror(errno)); return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/mkdirprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/mkdir </path/to/create-directory> </path/to/remove-directory> Examples: /home/local/code/ansiccode/sysdir/mkdir /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir2 /home/local/code/ansiccode/sysdir/mkdir /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir2 /home/local/code/ansiccode/sysdir/mkdir /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir1
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/mkdir /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir2 /home/local/code/ansiccode/sysdir/mkdir /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir2 /home/local/code/ansiccode/sysdir/mkdir /home/local/code/ansiccode/sysdir/tempdir1 /home/local/code/ansiccode/sysdir/tempdir1rezultat będzie zależny od podanych argumentów wywołania programu:
mkdir: result=mkdir(argv[1]=/home/local/code/ansiccode/sysdir/tempdir1, varumask=755): mkdir: result=mkdir(argv[1]=/home/local/code/ansiccode/sysdir/tempdir1, varumask=755): result=-1 if (result>=0): else: Unable to mkdir(), Reason: 17:File exists mkdir: result=rmdir(argv[2]=/home/local/code/ansiccode/sysdir/tempdir2): mkdir: result=rmdir(argv[2]=/home/local/code/ansiccode/sysdir/tempdir2): result=-1 if (result>=0): else: Unable to rmdir(), Reason: 2:No such file or directory mkdir: result=mkdir(argv[1]=/home/local/code/ansiccode/sysdir/tempdir1, varumask=755): mkdir: result=mkdir(argv[1]=/home/local/code/ansiccode/sysdir/tempdir1, varumask=755): result=-1 if (result>=0): else: Unable to mkdir(), Reason: 17:File exists mkdir: result=rmdir(argv[2]=/home/local/code/ansiccode/sysdir/tempdir2): mkdir: result=rmdir(argv[2]=/home/local/code/ansiccode/sysdir/tempdir2): result=-1 if (result>=0): else: Unable to rmdir(), Reason: 2:No such file or directory mkdir: result=mkdir(argv[1]=/home/local/code/ansiccode/sysdir/tempdir1, varumask=755): mkdir: result=mkdir(argv[1]=/home/local/code/ansiccode/sysdir/tempdir1, varumask=755): result=-1 if (result>=0): else: Unable to mkdir(), Reason: 17:File exists mkdir: result=rmdir(argv[2]=/home/local/code/ansiccode/sysdir/tempdir1): mkdir: result=rmdir(argv[2]=/home/local/code/ansiccode/sysdir/tempdir1): result=0 if (result>=0): Successful rmdir().
#top mkdirat¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
mkdirat()
znajduje się w pliku nagłówkowym sys/stat.h
.Deklaracja funkcji
mkdirat()
jest następująca:#ifdef __USE_ATFILE /* Like mkdir(), create a new directory with permission bits MODE. But interpret relative PATH names relative to the directory associated with FD. */ extern int mkdirat (int __fd, __const char *__path, __mode_t __mode) __THROW __nonnull ((2)); #endif
Powiązane:
mkdir(), mkdirat(), rmdir(),
Opis:
Funkcja mkdirat() analogicznie jak funkcja mkdir() tworzy katalog oraz ustawia uprawnienia utworzonego katalogu, jednakże w odróżnieniu do funkcji mkdir() podana w argumencie nazwa katalogu __path interpretowana jest relatywnie do deksryptora przekazanego w argumencie __fd. W przypadku sukcesu wykonania operacji funkcja zwraca wartość 0, w przeciwnym przypadku funkcja zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
int __fd - deskryptor określający katalog względem którego tworzony jest nowy katalog.
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający nazwę tworzonego katalogu.
__mode_t __mode - uprawnienia utworzonego katalogu.
Zwracana wartość:
int - status wynonania operacji: 0 w przypadku sukcesu, -1 w przypadku wystąpienia błędu.
Argumenty:
int __fd - deskryptor określający katalog względem którego tworzony jest nowy katalog.
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający nazwę tworzonego katalogu.
__mode_t __mode - uprawnienia utworzonego katalogu.
Zwracana wartość:
int - status wynonania operacji: 0 w przypadku sukcesu, -1 w przypadku wystąpienia błędu.
#top opendir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
opendir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
opendir()
jest następująca:/* Open a directory stream on NAME. Return a DIR stream on the directory, or NULL if it could not be opened. This function is a possible cancellation point and therefore not marked with __THROW. */ extern DIR *opendir (__const char *__name) __nonnull ((1));
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja opendir() otwiera katalog wskazywane przez ścieżkę podaną w argumencie __name. W przypadku sukcesu funkcja opendir() zwraca deskryptor do otwartego katalogu. W przypadku wystąpienia błędu funkcja zwraca wartość NULL oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
const char *__name - łańuch znaków (wskaźnik do łańcucha znaków) określający ścieżkę katalogu, który zostanie otwarty.
Zwracana wartość:
DIR * - deskryptor otwartego katalogu w przypadku sukcesu, NULL w przypadku wystąpienia błędu.
Argumenty:
const char *__name - łańuch znaków (wskaźnik do łańcucha znaków) określający ścieżkę katalogu, który zostanie otwarty.
Zwracana wartość:
DIR * - deskryptor otwartego katalogu w przypadku sukcesu, NULL w przypadku wystąpienia błędu.
Example:
zawartość pliku
opendir.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ int main(int argc, char **argv) { char *self; DIR *dirfd; struct dirent *dirrow; int result; int i; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); return 0; } dirfd=opendir(argv[1]); if (dirfd != NULL) { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): Successful opendir().\n", self, argv[1], (void*)dirfd); i=0; printf("%s: while ((dirrow=readdir(dirfd)) != NULL):\n", self); while ((dirrow=readdir(dirfd)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd)); #else printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd)); #endif } /* rewinddir/seekdir */ /* rewinddir/seekdir */ i=0; printf("%s: while ((dirrow=readdir(dirfd)) != NULL):\n", self); while ((dirrow=readdir(dirfd)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd)); #else printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd)); #endif } result=closedir(dirfd); if (result>=0) printf("%s: result=closedir(dirfd): result=%d if (result>=0): Successful closedir().\n", self, result); else printf("%s: result=closedir(dirfd): result=%d if (result>=0): else: Unable to closedir(), Reason: %d:%s\n", self, result, errno, strerror(errno)); } else { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): else: Unable to opendir(), Reason: %d:%s\n", self, argv[1], (void*)dirfd, errno, strerror(errno)); } return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/opendirprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/opendir </path/to/directory>
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/opendir /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
opendir: dirfd=opendir(workdir=/home/local/code/ansiccode/sysdir): dirfd=0x8f66008 if (dirfd != NULL): Successful opendir(). opendir: while ((dirrow=readdir(dirfd)) != NULL): opendir: [0] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 telldir(dirfd)=111075960 opendir: [1] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 telldir(dirfd)=123907409 opendir: [2] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1410540 telldir(dirfd)=147508333 opendir: [3] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 telldir(dirfd)=258066785 opendir: [4] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=340175332 dirrow->d_ino=1410387 telldir(dirfd)=340175332 opendir: [5] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=427406474 dirrow->d_ino=1410445 telldir(dirfd)=427406474 opendir: [6] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 telldir(dirfd)=495216175 opendir: [7] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 telldir(dirfd)=625605754 opendir: [8] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 telldir(dirfd)=661949438 opendir: [9] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410321 telldir(dirfd)=679195114 opendir: [10] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 telldir(dirfd)=679233412 opendir: [11] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=718026284 dirrow->d_ino=1410448 telldir(dirfd)=718026284 opendir: [12] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 telldir(dirfd)=753056283 opendir: [13] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 telldir(dirfd)=866081774 opendir: [14] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 telldir(dirfd)=1049513945 opendir: [15] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 telldir(dirfd)=1165269826 opendir: [16] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 telldir(dirfd)=1166638244 opendir: [17] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1345128052 dirrow->d_ino=1410440 telldir(dirfd)=1345128052 opendir: [18] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410392 telldir(dirfd)=1481921411 opendir: [19] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1638081534 dirrow->d_ino=1409388 telldir(dirfd)=1638081534 opendir: [20] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410275 telldir(dirfd)=1786084748 opendir: [21] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 telldir(dirfd)=1788532095 opendir: [22] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1410324 telldir(dirfd)=1967637597 opendir: [23] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2010445905 dirrow->d_ino=1410326 telldir(dirfd)=2010445905 opendir: [24] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 telldir(dirfd)=2069417274 opendir: [25] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 telldir(dirfd)=2099643303 opendir: [26] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410538 telldir(dirfd)=2147483647 opendir: while ((dirrow=readdir(dirfd)) != NULL): opendir: result=closedir(dirfd): result=0 if (result>=0): Successful closedir().
#top readdir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
readdir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
readdir()
jest następująca:/* Read a directory entry from DIRP. Return a pointer to a `struct dirent' describing the entry, or NULL for EOF or error. The storage returned may be overwritten by a later readdir call on the same DIR stream. If the Large File Support API is selected we have to use the appropriate interface. This function is a possible cancellation point and therefore not marked with __THROW. */ extern struct dirent *readdir (DIR *__dirp) __nonnull ((1));
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja readdir() odczytuje jeden element z katalogu (jeden wiersz / jedną pozycję) wskazywanego przez deskryptor przekazany w argumencie__dirp. Informacja zwracana jest w postaci wskaźnika do struktury struct dirent zawierającej informacje o odczytanym elemencie katalogu. Kolejne sekwencyjne wywołania funkcji odczytują kolejne elementy katalogu. Po odczytaniu wszystkich elementów z katalogu ostatnie wywołanie funkcji zwraca NULL. W przypadku wystąpienia błędu funkcja również zwraca NULL oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
DIR *__dirp - deskryptor katalogu z którego zostaną odczytane kolejne elementy.
Zwracana wartość:
struct dirent * - wskaźnik do struktury zawierającej informacje o odczytanym elemencie katalogu.
Argumenty:
DIR *__dirp - deskryptor katalogu z którego zostaną odczytane kolejne elementy.
Zwracana wartość:
struct dirent * - wskaźnik do struktury zawierającej informacje o odczytanym elemencie katalogu.
#top rewinddir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
rewinddir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
rewinddir()
jest następująca:/* Rewind DIRP to the beginning of the directory. */ extern void rewinddir (DIR *__dirp) __THROW __nonnull ((1));
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja rewinddir() jest używana do "przewijania" katalogu do początku, czyli ustawia pozycję deskryptora katalogu przekazanego w argumencie __dirp (jest równoważna do seekdir(__dirp, 0)). Funkcja najczęściej jest używana w przypadku kiedy zostaną odczytane wszystkie elementy z katalogu, wtedy kolejne wywołania funkcji readdir() zwracają NULL, wywołanie funkcji rewinddir() umożliwia ponowny odczyt elementów z katalogu, analogicznie jak po otwarciu katalogu funkcją opendir().
Argumenty:
DIR *__dirp - deskryptor katalogu dla którego pozycja zostanie ustawiona na początku.
Zwracana wartość:
Funkcja nie zwraca żadnej wartości.
Argumenty:
DIR *__dirp - deskryptor katalogu dla którego pozycja zostanie ustawiona na początku.
Zwracana wartość:
Funkcja nie zwraca żadnej wartości.
Example:
zawartość pliku
rewinddir.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ int main(int argc, char **argv) { char *self; DIR *dirfd; struct dirent *dirrow; int result; int i; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); return 0; } dirfd=opendir(argv[1]); if (dirfd != NULL) { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): Successful opendir().\n", self, argv[1], (void*)dirfd); i=0; printf("%s: while ((dirrow=readdir(dirfd)) != NULL):\n", self); while ((dirrow=readdir(dirfd)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd)); #else printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd)); #endif } printf("%s: rewinddir(dirfd=%p):\n", self, (void*)dirfd); rewinddir(dirfd); i=0; printf("%s: while ((dirrow=readdir(dirfd)) != NULL):\n", self); while ((dirrow=readdir(dirfd)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd)); #else printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd)); #endif } result=closedir(dirfd); if (result>=0) printf("%s: result=closedir(dirfd): result=%d if (result>=0): Successful closedir().\n", self, result); else printf("%s: result=closedir(dirfd): result=%d if (result>=0): else: Unable to closedir(), Reason: %d:%s\n", self, result, errno, strerror(errno)); } else { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): else: Unable to opendir(), Reason: %d:%s\n", self, argv[1], (void*)dirfd, errno, strerror(errno)); } return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/rewinddirprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/rewinddir </path/to/directory>
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/rewinddir /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
rewinddir: dirfd=opendir(workdir=/home/local/code/ansiccode/sysdir): dirfd=0x9132008 if (dirfd != NULL): Successful opendir(). rewinddir: while ((dirrow=readdir(dirfd)) != NULL): rewinddir: [0] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 telldir(dirfd)=111075960 rewinddir: [1] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 telldir(dirfd)=123907409 rewinddir: [2] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1410540 telldir(dirfd)=147508333 rewinddir: [3] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 telldir(dirfd)=258066785 rewinddir: [4] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=340175332 dirrow->d_ino=1410387 telldir(dirfd)=340175332 rewinddir: [5] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=427406474 dirrow->d_ino=1410445 telldir(dirfd)=427406474 rewinddir: [6] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 telldir(dirfd)=495216175 rewinddir: [7] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 telldir(dirfd)=625605754 rewinddir: [8] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 telldir(dirfd)=661949438 rewinddir: [9] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410321 telldir(dirfd)=679195114 rewinddir: [10] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 telldir(dirfd)=679233412 rewinddir: [11] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=718026284 dirrow->d_ino=1410448 telldir(dirfd)=718026284 rewinddir: [12] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 telldir(dirfd)=753056283 rewinddir: [13] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 telldir(dirfd)=866081774 rewinddir: [14] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 telldir(dirfd)=1049513945 rewinddir: [15] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 telldir(dirfd)=1165269826 rewinddir: [16] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 telldir(dirfd)=1166638244 rewinddir: [17] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1345128052 dirrow->d_ino=1410440 telldir(dirfd)=1345128052 rewinddir: [18] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410392 telldir(dirfd)=1481921411 rewinddir: [19] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1638081534 dirrow->d_ino=1409388 telldir(dirfd)=1638081534 rewinddir: [20] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410275 telldir(dirfd)=1786084748 rewinddir: [21] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 telldir(dirfd)=1788532095 rewinddir: [22] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1410324 telldir(dirfd)=1967637597 rewinddir: [23] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2010445905 dirrow->d_ino=1410326 telldir(dirfd)=2010445905 rewinddir: [24] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 telldir(dirfd)=2069417274 rewinddir: [25] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 telldir(dirfd)=2099643303 rewinddir: [26] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410538 telldir(dirfd)=2147483647 rewinddir: rewinddir(dirfd=0x9132008): rewinddir: while ((dirrow=readdir(dirfd)) != NULL): rewinddir: [0] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 telldir(dirfd)=111075960 rewinddir: [1] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 telldir(dirfd)=123907409 rewinddir: [2] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1410540 telldir(dirfd)=147508333 rewinddir: [3] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 telldir(dirfd)=258066785 rewinddir: [4] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=340175332 dirrow->d_ino=1410387 telldir(dirfd)=340175332 rewinddir: [5] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=427406474 dirrow->d_ino=1410445 telldir(dirfd)=427406474 rewinddir: [6] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 telldir(dirfd)=495216175 rewinddir: [7] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 telldir(dirfd)=625605754 rewinddir: [8] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 telldir(dirfd)=661949438 rewinddir: [9] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410321 telldir(dirfd)=679195114 rewinddir: [10] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 telldir(dirfd)=679233412 rewinddir: [11] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=718026284 dirrow->d_ino=1410448 telldir(dirfd)=718026284 rewinddir: [12] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 telldir(dirfd)=753056283 rewinddir: [13] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 telldir(dirfd)=866081774 rewinddir: [14] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 telldir(dirfd)=1049513945 rewinddir: [15] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 telldir(dirfd)=1165269826 rewinddir: [16] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 telldir(dirfd)=1166638244 rewinddir: [17] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1345128052 dirrow->d_ino=1410440 telldir(dirfd)=1345128052 rewinddir: [18] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410392 telldir(dirfd)=1481921411 rewinddir: [19] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1638081534 dirrow->d_ino=1409388 telldir(dirfd)=1638081534 rewinddir: [20] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410275 telldir(dirfd)=1786084748 rewinddir: [21] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 telldir(dirfd)=1788532095 rewinddir: [22] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1410324 telldir(dirfd)=1967637597 rewinddir: [23] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2010445905 dirrow->d_ino=1410326 telldir(dirfd)=2010445905 rewinddir: [24] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 telldir(dirfd)=2069417274 rewinddir: [25] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 telldir(dirfd)=2099643303 rewinddir: [26] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410538 telldir(dirfd)=2147483647 rewinddir: result=closedir(dirfd): result=0 if (result>=0): Successful closedir().
#top rmdir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
rmdir()
znajduje się w pliku nagłówkowym unistd.h
.Deklaracja funkcji
rmdir()
jest następująca:/* Remove the directory PATH. */ extern int rmdir (__const char *__path) __THROW __nonnull ((1));
Powiązane:
mkdir(), mkdirat(), rmdir(),
Opis:
Funkcja rmdir() usuwa katalog o nazwie podanej w argumencie __path. Usuwany katalog musi być pusty, aby operacja się powiodła. W przypadku sukcesu wykonania operacji funkcja zwraca wartość 0, w przeciwnym przypadku funkcja zwraca wartość -1 oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający nazwę usuwanego katalogu.
Zwracana wartość:
int - status wynonania operacji: 0 w przypadku sukcesu, -1 w przypadku wystąpienia błędu.
Argumenty:
const char *__path - łańcuch znaków (wskaźnik do łańcucha znaków) zawierający nazwę usuwanego katalogu.
Zwracana wartość:
int - status wynonania operacji: 0 w przypadku sukcesu, -1 w przypadku wystąpienia błędu.
#top scandir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
scandir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
scandir()
jest następująca:/* Scan the directory DIR, calling SELECTOR on each directory entry. Entries for which SELECT returns nonzero are individually malloc'd, sorted using qsort with CMP, and collected in a malloc'd array in *NAMELIST. Returns the number of entries selected, or -1 on error. */ extern int scandir (__const char *__restrict __dir, struct dirent ***__restrict __namelist, int (*__selector) (__const struct dirent *), int (*__cmp) (__const void *, __const void *)) __nonnull ((1, 2));
Powiązane:
alphasort(), getdents(), getdirentries(), glob(), globfree(), scandir(), versionsort(),
Opis:
Funkcja scandir() listuje zawartość katalogu (skanuje katalog) wywołując dla każdego elementu funkcję filtrującą przekazaną w argumencie __selector. Elementy dla których funkcja filtrująca __selector zwróci wartość 1 dodawane są do listy elementów przekazanej w argumencie __namelist zaalokowanej poprzez funkcję malloc() (po zakończeniu pracy ze zwróconą listą elementów niezbędne jest zwolnienie zaalokowanej pamięci wskazywanej przez wskaźnik __namelist poprzez wywołanie funkcji free() z argumentem zawierającym wskaźnik do zwróconej listy __namelist). Po zakończeniu listowania zawartości katalogu lista elementów przekazana w argumencie __namelist jest sortowana za pomocą funkcji qsort() z użyciem funkcji porównującej elementy przekazanej w argumencie __cmp. Jako wynik działania funkcja scandir() zwraca liczbę elementów umieszczonych na liście przekazanej w argumencie __namelist w przypadku sukcesu, w przypadku błędu funkcja zwraca -1 oraz oraz ustawia globalną zmienną errno na kod błędu zawierający przyczynę niepowodzenia opracji.
Argumenty:
const char *__restrict __dir - łańuch znaków (wskaźnik do łańcucha znaków) określający ścieżkę katalogu, który zostanie przeskanowany w celu wylistowania zawartości.
struct dirent ***__restrict __namelist - wskaźnik do listy elementow zwróconych przez funkcję, której przestrzeń zostanie zaalokowana przez funkcję malloc().
int (*__selector) (__const struct dirent *) - wskaźnik do funkcji filtrującej elementy (każdy element dla którego funkcja zwróci wartość różną od 0 jest dodawany do listy elementów przekazanej w argumencie __namelist).
int (*__cmp) (__const void *, __const void *) - wskaźnik do funkcji porównującej elementy katalogu, wywoływanej przez funkcję sortującą qsort() wylistowane elementy z katalogu określonego ścieżką przekazaną w argumencie __dir.
Zwracana wartość:
int - ilość elementów zwróconych na liści przekazanej w argumencie __namelist w przypadku sukcesu, w przypadku wystąpienia błędu -1.
Argumenty:
const char *__restrict __dir - łańuch znaków (wskaźnik do łańcucha znaków) określający ścieżkę katalogu, który zostanie przeskanowany w celu wylistowania zawartości.
struct dirent ***__restrict __namelist - wskaźnik do listy elementow zwróconych przez funkcję, której przestrzeń zostanie zaalokowana przez funkcję malloc().
int (*__selector) (__const struct dirent *) - wskaźnik do funkcji filtrującej elementy (każdy element dla którego funkcja zwróci wartość różną od 0 jest dodawany do listy elementów przekazanej w argumencie __namelist).
int (*__cmp) (__const void *, __const void *) - wskaźnik do funkcji porównującej elementy katalogu, wywoływanej przez funkcję sortującą qsort() wylistowane elementy z katalogu określonego ścieżką przekazaną w argumencie __dir.
Zwracana wartość:
int - ilość elementów zwróconych na liści przekazanej w argumencie __namelist w przypadku sukcesu, w przypadku wystąpienia błędu -1.
Example:
zawartość pliku
scandir.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ int dircmp(const void *voida, const void *voidb) { struct dirent *direa, *direb; direa=(struct dirent*)voida; direb=(struct dirent*)voidb; return strncmp( direa->d_name, direb->d_name, strlen(direa->d_name) > strlen(direb->d_name) ? strlen(direa->d_name) : strlen(direb->d_name) ); } int dirsel(const struct dirent *dirrow) { printf("dirsel(const struct dirent *dirrow): dires->d_name=%s\n", dirrow->d_name); if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) return 0; else return 1; } int main(int argc, char **argv) { char *self; struct dirent **dirlist; struct dirent *dirrow; int result; int i; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); return 0; } printf("%s: result=scandir(argv[1]=%s, &dirlist, &dirsel, &dircmp):\n", self, argv[1]); #if defined(HAVE_SCANDIR) result=scandir(argv[1], &dirlist, &dirsel, &dircmp); #else /* scandir() is not available on this OS platform !!! */ printf("%s: scandir() is not available on this OS platform !!!\n", self); result=-1; #endif if (result>=0) { printf("%s: result=scandir(argv[1]=%s, &dirlist, &dirsel, &dircmp): result=%d if (result>=0): Successful scandir().\n", self, argv[1], result); for (i=0;i<result;i++) { dirrow=dirlist[i]; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld\n", self, i, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino); #else printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld\n", self, i, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino); #endif } } else { printf("%s: dir=opendir(workdir=%s): result=%d if (dir != NULL): else: Unable to scandir(), Reason: %d:%s\n", self, argv[1], result, errno, strerror(errno)); } return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/scandirprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/scandir </path/to/directory>
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/scandir /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
scandir: result=scandir(argv[1]=/home/local/code/ansiccode/sysdir, &dirlist, &dirsel, &dircmp): dirsel(const struct dirent *dirrow): dires->d_name=closedir dirsel(const struct dirent *dirrow): dires->d_name=chroot dirsel(const struct dirent *dirrow): dires->d_name=Makefile.sol dirsel(const struct dirent *dirrow): dires->d_name=opendir.c dirsel(const struct dirent *dirrow): dires->d_name=readdir.c dirsel(const struct dirent *dirrow): dires->d_name=opendir dirsel(const struct dirent *dirrow): dires->d_name=readdir dirsel(const struct dirent *dirrow): dires->d_name=getcwd.c dirsel(const struct dirent *dirrow): dires->d_name=chroot.c dirsel(const struct dirent *dirrow): dires->d_name=Makefile.win dirsel(const struct dirent *dirrow): dires->d_name=chdir dirsel(const struct dirent *dirrow): dires->d_name=chdir.c dirsel(const struct dirent *dirrow): dires->d_name=rewinddir dirsel(const struct dirent *dirrow): dires->d_name=closedir.c dirsel(const struct dirent *dirrow): dires->d_name=getcwd dirsel(const struct dirent *dirrow): dires->d_name=.. dirsel(const struct dirent *dirrow): dires->d_name=scandir.c dirsel(const struct dirent *dirrow): dires->d_name=rewinddir.c dirsel(const struct dirent *dirrow): dires->d_name=Makefile dirsel(const struct dirent *dirrow): dires->d_name=scandir dirsel(const struct dirent *dirrow): dires->d_name=Makefile.fbsd dirsel(const struct dirent *dirrow): dires->d_name=Makefile.obsd dirsel(const struct dirent *dirrow): dires->d_name=obj dirsel(const struct dirent *dirrow): dires->d_name=. dirsel(const struct dirent *dirrow): dires->d_name=Makefile.beos scandir: result=scandir(argv[1]=/home/local/code/ansiccode/sysdir, &dirlist, &dirsel, &dircmp): result=48 if (result>=0): Successful scandir(). scandir: [00] dirrow->d_name=alphasort.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=427406474 dirrow->d_ino=1411008 scandir: [01] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 scandir: [02] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 scandir: [03] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1410495 scandir: [04] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410458 scandir: [05] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 scandir: [06] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=687030437 dirrow->d_ino=1410448 scandir: [07] dirrow->d_name=fdopendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=718026284 dirrow->d_ino=1410990 scandir: [08] dirrow->d_name=dirfd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=714692598 dirrow->d_ino=1411007 scandir: [09] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=326292342 dirrow->d_ino=1410387 scandir: [10] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1423750639 dirrow->d_ino=1410392 scandir: [11] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 scandir: [12] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410218 scandir: [13] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 scandir: [14] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2007201532 dirrow->d_ino=1409746 scandir: [15] dirrow->d_name=getdirentries.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1603650525 dirrow->d_ino=1410377 scandir: [16] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 scandir: [17] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 scandir: [18] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 scandir: [19] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 scandir: [20] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 scandir: [21] dirrow->d_name=glob.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=340175332 dirrow->d_ino=1411054 scandir: [22] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1172385886 dirrow->d_ino=1410440 scandir: [23] dirrow->d_name=fdopendir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410972 scandir: [24] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1558810147 dirrow->d_ino=1409388 scandir: [25] dirrow->d_name=glob dirrow->d_type=0x08 dirrow->d_reclen=16 dirrow->d_off=1345128052 dirrow->d_ino=1411025 scandir: [26] dirrow->d_name=glob-fnmatch dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1383606058 dirrow->d_ino=1411050 scandir: [27] dirrow->d_name=globfree dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1336351603 dirrow->d_ino=1411148 scandir: [28] dirrow->d_name=glob-fnmatch.c dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1638081534 dirrow->d_ino=1411180 scandir: [29] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1707577288 dirrow->d_ino=1410211 scandir: [30] dirrow->d_name=mkdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1771880146 dirrow->d_ino=1411061 scandir: [31] dirrow->d_name=dirfd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410758 scandir: [32] dirrow->d_name=mkdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1709357308 dirrow->d_ino=1411037 scandir: [33] dirrow->d_name=versionsort.c dirrow->d_type=0x0A dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1411051 scandir: [34] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=361703713 dirrow->d_ino=1410445 scandir: [35] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=130721592 dirrow->d_ino=1410336 scandir: [36] dirrow->d_name=versionsort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1411053 scandir: [37] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 scandir: [38] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 scandir: [39] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=118909187 dirrow->d_ino=1410401 scandir: [40] dirrow->d_name=globfree.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=123907409 dirrow->d_ino=1411134 scandir: [41] dirrow->d_name=rmdir.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=2010445905 dirrow->d_ino=1411023 scandir: [42] dirrow->d_name=mkdirat.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1903302723 dirrow->d_ino=1412361 scandir: [43] dirrow->d_name=rmdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1934495362 dirrow->d_ino=1411048 scandir: [44] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1409984 scandir: [45] dirrow->d_name=getdirentries dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1964717140 dirrow->d_ino=1410996 scandir: [46] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1853408271 dirrow->d_ino=1409753 scandir: [47] dirrow->d_name=alphasort dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1857803129 dirrow->d_ino=1410274
#top seekdir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
seekdir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
seekdir()
jest następująca:/* Seek to position POS on DIRP. */ extern void seekdir (DIR *__dirp, long int __pos) __THROW __nonnull ((1));
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja seekdir() jest używana do "przewijania" do pozycji (ustawiania na pozycji) określonej argumentem __pos deskryptora katalogu przekazanego w argumencie __dirp. W przypadku podania jako argument __pos pozycji 0 (wartości 0) rezultat wykonania funkcji będzie analogiczny do wywołania funkcji rewinddir().
Argumenty:
DIR *__dirp - deskryptor katalogu, którego pozycja zostanie ustawiona.
long int __pos - pozycja do ustawienia dla katalogu określonego deskryptorem przekazanym w argumencie __dirp.
Zwracana wartość:
Funkcja nie zwraca żadnej wartości.
Argumenty:
DIR *__dirp - deskryptor katalogu, którego pozycja zostanie ustawiona.
long int __pos - pozycja do ustawienia dla katalogu określonego deskryptorem przekazanym w argumencie __dirp.
Zwracana wartość:
Funkcja nie zwraca żadnej wartości.
Example:
zawartość pliku
seekdir.c
SELECT ALL
#define _GNU_SOURCE 1 /* for environ defined in unistd.h, to avoid warning implicit declaration of function basename, which defined in string.h */ #include <stdio.h> /* for FILE, va_list, EOF, SEEK_SET, SEEK_CUR, SEEK_END, stdin, stdout, stderr, remove(), rename(), tmpfile(), tmpnam(), tempnam(), fclose(), */ /* fflush(), fopen(), freopen(), fprintf(), printf(), snprintf(), scanf(), sscanf(), fgetc(), getc(), getchar(), fputc(), putc(), putchar(), */ /* fgets(), gets(), fputs(), puts(), fread(), fwrite(), fseek(), ftell(), rewind(), feof(), ferror(), fileno(), popen(), pclose(), */ #include <stdint.h> /* for INT(8|16|32|64)_MIN, INT(8|16|32|64)_MAX, UINT(8|16|32|64)_MAX, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, */ #include <string.h> /* for memcpy(), memmove(), memset(), memcmp(), memchr(), memrchr(), str[n]cpy(), str[n]cat(), str[n]cmp(), strcoll(), str[n]dup(), strchr(), strrchr(), strstr(), */ /* strtok(), strcasestr(), memmem(), mempcpy(), str[n]len(), strerror(), bcopy(), bzero(), strcasecmp(), strsep(), basename(), */ #include <unistd.h> /* for R_OK, W_OK, X_OK, F_OK, environ, access(), lseek(), close(), read(), write(), pipe(), alarm(), sleep(), ualarm(), usleep(), pause(), chown(), chdir(), getcwd(), */ /* for exec[...](), nice(), getpid(), getppid(), setpgid(), setsid(), getsid(), getuid(), geteuid(). getgid(), getegid(), setuid(), seteuid(), setgid(), setegid(), fork(), */ /* for link(), symlink(), readlink(), unlink(), rmdir(), getlogin(), setlogin(), gethostname(), sethostname(), daemon(), chroot(), getpass(), [f]sync(), [f]truncate(), syscall(), */ #include <errno.h> /* for errno constant, error constants, */ #include <dirent.h> /* for struct __dirstream DIR, opendir(), closedir(), readdir(), rewinddir(), seekdir(), telldir(), scandir(), alphasort(), versionsort(), getdirentries(), */ int main(int argc, char **argv) { char *self; DIR *dirfd; struct dirent *dirrow; int result; int i; self=strrchr(argv[0], '/'); if (self!=NULL) self++; else self=argv[0]; if (argc<2) { printf("Usage: %s </path/to/directory>\n", argv[0]); return 0; } dirfd=opendir(argv[1]); if (dirfd != NULL) { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): Successful opendir().\n", self, argv[1], (void*)dirfd); i=0; printf("%s: while ((dirrow=readdir(dirfd)) != NULL):\n", self); while ((dirrow=readdir(dirfd)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd)); #else printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd)); #endif } printf("%s: seekdir(dirfd=%p, 0):\n", self, (void*)dirfd); seekdir(dirfd, 0); i=0; printf("%s: while ((dirrow=readdir(dirfd)) != NULL):\n", self); while ((dirrow=readdir(dirfd)) != NULL) { if ((strlen(dirrow->d_name)==1&&strncmp(dirrow->d_name,".",1)==0) || (strlen(dirrow->d_name)==2&&strncmp(dirrow->d_name,"..",2)==0)) continue; #if defined(HAVE_DIRENT_TYPEOFF) printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_type=0x%02X dirrow->d_reclen=%d dirrow->d_off=%lld dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_type, dirrow->d_reclen, (int64_t)dirrow->d_off, (int64_t)dirrow->d_ino, telldir(dirfd)); #else printf("%s: [%d] dirrow->d_name=%-20s dirrow->d_reclen=%d dirrow->d_ino=%lld telldir(dirfd)=%ld\n", self, i++, dirrow->d_name, dirrow->d_reclen, (int64_t)dirrow->d_ino, telldir(dirfd)); #endif } result=closedir(dirfd); if (result>=0) printf("%s: result=closedir(dirfd): result=%d if (result>=0): Successful closedir().\n", self, result); else printf("%s: result=closedir(dirfd): result=%d if (result>=0): else: Unable to closedir(), Reason: %d:%s\n", self, result, errno, strerror(errno)); } else { printf("%s: dirfd=opendir(workdir=%s): dirfd=%p if (dirfd != NULL): else: Unable to opendir(), Reason: %d:%s\n", self, argv[1], (void*)dirfd, errno, strerror(errno)); } return 0; }
program należy skompilować komendą make (jako argument należy podać plik
Makefile
zależny od systemu operacyjnego, domyślnie make próbuje użyć pliku Makefile
):make clean all # system Linux make -f Makefile clean all # system Linux make -f Makefile.obsd clean all # system OpenBSD make -f Makefile.fbsd clean all # system FreeBSD make -f Makefile.sol clean all # system Solaris make -f Makefile.beos clean all # system BeOS make -f Makefile.win clean all # system Windows
a następnie uruchomić bez argumentów:
/home/local/code/ansiccode/sysdir/seekdirprogram wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/ansiccode/sysdir/seekdir </path/to/directory>
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/ansiccode/sysdir/seekdir /home/local/code/ansiccode/sysdirrezultat będzie zależny od podanych argumentów wywołania programu:
seekdir: dirfd=opendir(workdir=/home/local/code/ansiccode/sysdir): dirfd=0x8acb008 if (dirfd != NULL): Successful opendir(). seekdir: while ((dirrow=readdir(dirfd)) != NULL): seekdir: [0] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 telldir(dirfd)=111075960 seekdir: [1] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 telldir(dirfd)=123907409 seekdir: [2] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1410540 telldir(dirfd)=147508333 seekdir: [3] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 telldir(dirfd)=258066785 seekdir: [4] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=340175332 dirrow->d_ino=1410387 telldir(dirfd)=340175332 seekdir: [5] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=427406474 dirrow->d_ino=1410445 telldir(dirfd)=427406474 seekdir: [6] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 telldir(dirfd)=495216175 seekdir: [7] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 telldir(dirfd)=625605754 seekdir: [8] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 telldir(dirfd)=661949438 seekdir: [9] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410321 telldir(dirfd)=679195114 seekdir: [10] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 telldir(dirfd)=679233412 seekdir: [11] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=718026284 dirrow->d_ino=1410448 telldir(dirfd)=718026284 seekdir: [12] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 telldir(dirfd)=753056283 seekdir: [13] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 telldir(dirfd)=866081774 seekdir: [14] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 telldir(dirfd)=1049513945 seekdir: [15] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 telldir(dirfd)=1165269826 seekdir: [16] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 telldir(dirfd)=1166638244 seekdir: [17] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1345128052 dirrow->d_ino=1410440 telldir(dirfd)=1345128052 seekdir: [18] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410392 telldir(dirfd)=1481921411 seekdir: [19] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1638081534 dirrow->d_ino=1409388 telldir(dirfd)=1638081534 seekdir: [20] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410275 telldir(dirfd)=1786084748 seekdir: [21] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 telldir(dirfd)=1788532095 seekdir: [22] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1410324 telldir(dirfd)=1967637597 seekdir: [23] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2010445905 dirrow->d_ino=1410326 telldir(dirfd)=2010445905 seekdir: [24] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 telldir(dirfd)=2069417274 seekdir: [25] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 telldir(dirfd)=2099643303 seekdir: [26] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410538 telldir(dirfd)=2147483647 seekdir: seekdir(dirfd=0x8acb008, 0): seekdir: while ((dirrow=readdir(dirfd)) != NULL): seekdir: [0] dirrow->d_name=closedir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=111075960 dirrow->d_ino=1410423 telldir(dirfd)=111075960 seekdir: [1] dirrow->d_name=chroot dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=123907409 dirrow->d_ino=1410401 telldir(dirfd)=123907409 seekdir: [2] dirrow->d_name=Makefile.sol dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=147508333 dirrow->d_ino=1410540 telldir(dirfd)=147508333 seekdir: [3] dirrow->d_name=opendir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=258066785 dirrow->d_ino=1410949 telldir(dirfd)=258066785 seekdir: [4] dirrow->d_name=readdir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=340175332 dirrow->d_ino=1410387 telldir(dirfd)=340175332 seekdir: [5] dirrow->d_name=opendir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=427406474 dirrow->d_ino=1410445 telldir(dirfd)=427406474 seekdir: [6] dirrow->d_name=readdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=495216175 dirrow->d_ino=1410447 telldir(dirfd)=495216175 seekdir: [7] dirrow->d_name=getcwd.c dirrow->d_type=0x0A dirrow->d_reclen=20 dirrow->d_off=625605754 dirrow->d_ino=1410464 telldir(dirfd)=625605754 seekdir: [8] dirrow->d_name=chroot.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=661949438 dirrow->d_ino=1411034 telldir(dirfd)=661949438 seekdir: [9] dirrow->d_name=Makefile.win dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=679195114 dirrow->d_ino=1410321 telldir(dirfd)=679195114 seekdir: [10] dirrow->d_name=chdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=679233412 dirrow->d_ino=1410348 telldir(dirfd)=679233412 seekdir: [11] dirrow->d_name=chdir.c dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=718026284 dirrow->d_ino=1410448 telldir(dirfd)=718026284 seekdir: [12] dirrow->d_name=telldir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=753056283 dirrow->d_ino=1411021 telldir(dirfd)=753056283 seekdir: [13] dirrow->d_name=seekdir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=866081774 dirrow->d_ino=1410380 telldir(dirfd)=866081774 seekdir: [14] dirrow->d_name=rewinddir dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1049513945 dirrow->d_ino=1410456 telldir(dirfd)=1049513945 seekdir: [15] dirrow->d_name=seekdir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1165269826 dirrow->d_ino=1411019 telldir(dirfd)=1165269826 seekdir: [16] dirrow->d_name=closedir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=1166638244 dirrow->d_ino=1410463 telldir(dirfd)=1166638244 seekdir: [17] dirrow->d_name=getcwd dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1345128052 dirrow->d_ino=1410440 telldir(dirfd)=1345128052 seekdir: [18] dirrow->d_name=scandir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1481921411 dirrow->d_ino=1410392 telldir(dirfd)=1481921411 seekdir: [19] dirrow->d_name=rewinddir.c dirrow->d_type=0x08 dirrow->d_reclen=24 dirrow->d_off=1638081534 dirrow->d_ino=1409388 telldir(dirfd)=1638081534 seekdir: [20] dirrow->d_name=Makefile dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1786084748 dirrow->d_ino=1410275 telldir(dirfd)=1786084748 seekdir: [21] dirrow->d_name=scandir dirrow->d_type=0x08 dirrow->d_reclen=20 dirrow->d_off=1788532095 dirrow->d_ino=1410460 telldir(dirfd)=1788532095 seekdir: [22] dirrow->d_name=Makefile.fbsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=1967637597 dirrow->d_ino=1410324 telldir(dirfd)=1967637597 seekdir: [23] dirrow->d_name=Makefile.obsd dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2010445905 dirrow->d_ino=1410326 telldir(dirfd)=2010445905 seekdir: [24] dirrow->d_name=telldir.c dirrow->d_type=0x0A dirrow->d_reclen=24 dirrow->d_off=2069417274 dirrow->d_ino=1410690 telldir(dirfd)=2069417274 seekdir: [25] dirrow->d_name=obj dirrow->d_type=0x04 dirrow->d_reclen=16 dirrow->d_off=2099643303 dirrow->d_ino=1410744 telldir(dirfd)=2099643303 seekdir: [26] dirrow->d_name=Makefile.beos dirrow->d_type=0x08 dirrow->d_reclen=28 dirrow->d_off=2147483647 dirrow->d_ino=1410538 telldir(dirfd)=2147483647 seekdir: result=closedir(dirfd): result=0 if (result>=0): Successful closedir().
#top telldir¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
telldir()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
telldir()
jest następująca:/* Return the current position of DIRP. */ extern long int telldir (DIR *__dirp) __THROW __nonnull ((1));
Powiązane:
closedir(), dirfd(), fdopendir(), opendir(), readdir(), rewinddir(), seekdir(), telldir(),
Opis:
Funkcja telldir() zwraca pozycję dla deskryptora katalogu określonego argumentem __dirp (wykonuje operację przeciwną do funkcji seekdir() w połączeniu z którą może być używana).
Argumenty:
DIR *__dirp - deskryptor katalogu dla którego zostanie zwrócona pozycja.
Zwracana wartość:
long int - pozycja w katalogu określonego argumentem __dirp.
Argumenty:
DIR *__dirp - deskryptor katalogu dla którego zostanie zwrócona pozycja.
Zwracana wartość:
long int - pozycja w katalogu określonego argumentem __dirp.
#top versionsort¶
Documentacja online: pubs.opengroup.org | www.cplusplus.com | pl.wikibooks.org | www.opennet.ru
Deklaracja funkcji
versionsort()
znajduje się w pliku nagłówkowym dirent.h
.Deklaracja funkcji
versionsort()
jest następująca:# ifdef __USE_GNU /* Function to compare two `struct dirent's by name & version. *: # ifndef __USE_FILE_OFFSET64 extern int versionsort (__const void *__e1, __const void *__e2) __THROW __attribute_pure__ __nonnull ((1, 2)); # else # ifdef __REDIRECT extern int __REDIRECT_NTH (versionsort, (__const void *__e1, __const void *__e2), versionsort64) __attribute_pure__ __nonnull ((1, 2)); # else # define versionsort versionsort64 # endif # endif
Powiązane:
alphasort(), getdents(), getdirentries(), glob(), globfree(), scandir(), versionsort(),
Opis:
Funkcja versionsort() została zaimplementowana w celu porównywania elementów typu struct dirent w funkcji sortującej umożliwiając tym samym sortowanie wyników zawartości katalogu (odczytanych funckją np: scandir() przyjmującą jako jeden z argumentów wskaźnik do funkcji porównującej kolejne elementy zawartości katalogu). Porównywanie realizowane jest poprzez wywoływanie funkcji strverscmp() z argumentem d_name struktury struct dirent.
Argumenty:
const void *__e1 - element porównywany z elementem przekazanym w argumencie __e2.
const void *__e2 - element porównywany z elementem przekazanym w argumencie __e1.
Zwracana wartość:
int - wynik porównania pól d_name struktury struct dirent przekazanych do funkcji w argumentach wywołania __e1 i __e2.
Argumenty:
const void *__e1 - element porównywany z elementem przekazanym w argumencie __e2.
const void *__e2 - element porównywany z elementem przekazanym w argumencie __e1.
Zwracana wartość:
int - wynik porównania pól d_name struktury struct dirent przekazanych do funkcji w argumentach wywołania __e1 i __e2.
Zmodyfikowany ostatnio: 2015/07/10 15:36:29 (9 lat temu),
textsize: 244 kB,
htmlsize: 320 kB
Zapraszam do komentowania, zgłaszania sugestii, propozycji, własnych przykładów, ...
Dodaj komentarzKomentarze użytkowników