| | 1 | /* |
| | 2 | * This file is part of Jam - see jam.c for Copyright information. |
| | 3 | */ |
| | 4 | |
| | 5 | #include "jam.h" |
| | 6 | |
| | 7 | #if defined(OS_AMIGA) |
| | 8 | |
| | 9 | #include "filesys.h" |
| | 10 | #include "strings.h" |
| | 11 | #include "pathsys.h" |
| | 12 | |
| | 13 | #include <stdio.h> |
| | 14 | #include <dirent.h> |
| | 15 | #include <sys/types.h> |
| | 16 | #include <sys/stat.h> |
| | 17 | |
| | 18 | /* |
| | 19 | * fileamiga.c - manipulate file names and scan directories on AmigaOS |
| | 20 | * |
| | 21 | * External routines: |
| | 22 | * |
| | 23 | * file_dirscan() - scan a directory for files |
| | 24 | * file_time() - get timestamp of file, if not done by file_dirscan() |
| | 25 | * file_archscan() - scan an archive for files |
| | 26 | * |
| | 27 | * File_dirscan() and file_archscan() call back a caller provided function |
| | 28 | * for each file found. A flag to this callback function lets file_dirscan() |
| | 29 | * and file_archscan() indicate that a timestamp is being provided with the |
| | 30 | * file. If file_dirscan() or file_archscan() do not provide the file's |
| | 31 | * timestamp, interested parties may later call file_time(). |
| | 32 | */ |
| | 33 | |
| | 34 | /* |
| | 35 | * file_dirscan() - scan a directory for files |
| | 36 | */ |
| | 37 | void file_dirscan(char *dir, scanback func, void *closure) |
| | 38 | { |
| | 39 | PATHNAME f; |
| | 40 | DIR *d; |
| | 41 | struct dirent *dirent; |
| | 42 | string filename[1]; |
| | 43 | |
| | 44 | /* First enter directory itself */ |
| | 45 | memset((char*)&f, '\0', sizeof(f)); |
| | 46 | f.f_dir.ptr = dir; |
| | 47 | f.f_dir.len = strlen(dir); |
| | 48 | |
| | 49 | dir = *dir ? dir : "."; |
| | 50 | |
| | 51 | /* Special case / : enter it */ |
| | 52 | if ( f.f_dir.len == 1 && f.f_dir.ptr[0] == '/' ) |
| | 53 | { |
| | 54 | (*func)(closure, dir, 0 /* not stat()'ed */, (time_t)0); |
| | 55 | } |
| | 56 | |
| | 57 | /* Now enter contents of directory */ |
| | 58 | if ( !(d = opendir(dir)) ) |
| | 59 | { |
| | 60 | return; |
| | 61 | } |
| | 62 | |
| | 63 | if ( DEBUG_BINDSCAN ) |
| | 64 | { |
| | 65 | printf("scan directory %s\n", dir); |
| | 66 | } |
| | 67 | |
| | 68 | string_new(filename); |
| | 69 | |
| | 70 | while ( dirent = readdir(d) ) |
| | 71 | { |
| | 72 | f.f_base.ptr = dirent->d_name; |
| | 73 | f.f_base.len = strlen(f.f_base.ptr); |
| | 74 | |
| | 75 | string_truncate(filename, 0); |
| | 76 | path_build(&f, filename, 0); |
| | 77 | |
| | 78 | (*func)(closure, filename->value, 0 /* not stat()'ed */, (time_t)0); |
| | 79 | } |
| | 80 | |
| | 81 | string_free(filename); |
| | 82 | |
| | 83 | closedir(d); |
| | 84 | } |
| | 85 | |
| | 86 | |
| | 87 | /* |
| | 88 | * file_time() - get timestamp of file, if not done by file_dirscan() |
| | 89 | */ |
| | 90 | int file_time(char *filename, time_t *time) |
| | 91 | { |
| | 92 | struct stat statbuf; |
| | 93 | |
| | 94 | if ( stat(filename, &statbuf) < 0 ) |
| | 95 | { |
| | 96 | return -1; |
| | 97 | } |
| | 98 | |
| | 99 | *time = statbuf.st_mtime; |
| | 100 | |
| | 101 | return 0; |
| | 102 | } |
| | 103 | |
| | 104 | |
| | 105 | int file_is_file(char* filename) |
| | 106 | { |
| | 107 | struct stat statbuf; |
| | 108 | |
| | 109 | if( stat( filename, &statbuf ) < 0 ) |
| | 110 | { |
| | 111 | return -1; |
| | 112 | } |
| | 113 | |
| | 114 | if (S_ISREG(statbuf.st_mode)) |
| | 115 | { |
| | 116 | return 1; |
| | 117 | } |
| | 118 | else |
| | 119 | { |
| | 120 | return 0; |
| | 121 | } |
| | 122 | } |
| | 123 | |
| | 124 | |
| | 125 | /* |
| | 126 | * file_archscan() - scan an archive for files |
| | 127 | */ |
| | 128 | void file_archscan(char *archive, scanback func, void *closure ) |
| | 129 | { |
| | 130 | } |
| | 131 | |
| | 132 | #endif |