/* WARNING: This file was generated by dkct. Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4fileig8.ctr */ /* Copyright (C) 2015-2017, Dirk Krause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above opyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file dk4fileig8.c The dk4fileig8 module. */ #line 10 "dk4fileig8.ctr" #include "dk4filei.h" #ifndef DK4TIME_H_INCLUDED #include "dk4time.h" #endif #ifndef DK4MEM_H_INCLUDED #include "dk4mem.h" #endif #ifndef DK4TIME08_H_INCLUDED #include "dk4time08.h" #endif #if DK4_TIME_WITH_SYS_TIME #ifndef SYS_TIME_H_INCLUDED #include #define SYS_TIME_H_INCLUDED 1 #endif #ifndef TIME_H_INCLUDED #include #define TIME_H_INCLUDED 1 #endif #else #if DK4_HAVE_TIME_H #ifndef TIME_H_INCLUDED #include #define TIME_H_INCLUDED 1 #endif #else #if DK4_HAVE_SYS_TIME_H #ifndef SYS_TIME_H_INCLUDED #include #define SYS_TIME_H_INCLUDED 1 #endif #endif #endif #endif #line 53 "dk4fileig8.ctr" #if DK4_ON_WINDOWS /* +++++ Windows +++++ */ static int dk4fileinfo_c8_filetime_timestamp( char *dptr, size_t szdptr, const FILETIME *timer, dk4_er_t *erp ) { SYSTEMTIME st; SYSTEMTIME lt; int back = 0; if (FileTimeToSystemTime(timer, &st)) { if (SystemTimeToTzSpecificLocalTime(NULL, &st, <)) { back = dk4time_to_text_c8( dptr, szdptr, DK4_TIMEFORMAT_DATE_TIME, lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, erp ); } else { dk4error_set_simple_error_code(erp, DK4_E_BUG); } } else { dk4error_set_simple_error_code(erp, DK4_E_BUG); } return back; } static int dk4fileinfo_c8_win_timestamp( char *dptr, size_t szdptr, const BY_HANDLE_FILE_INFORMATION *pbhfi, int chtime, dk4_er_t *erp ) { int back = 0; switch (chtime) { case DK4_FILE_INFO_TIME_ACCESS: { back = dk4fileinfo_c8_filetime_timestamp( dptr, szdptr, &(pbhfi->ftLastAccessTime), erp ); } break; case DK4_FILE_INFO_TIME_CREATE: { back = dk4fileinfo_c8_filetime_timestamp( dptr, szdptr, &(pbhfi->ftCreationTime), erp ); } break; default: { back = dk4fileinfo_c8_filetime_timestamp( dptr, szdptr, &(pbhfi->ftLastWriteTime), erp ); } break; } return back; } /* ----- Windows ----- */ #else /* +++++ non-Windows +++++ */ static int dk4fileinfo_c8_stat_time_timestamp( char *dptr, size_t szdptr, const time_t *timer, dk4_er_t *erp ) { #if DK4_HAVE_LOCALTIME_R struct tm lct; int back = 0; if (NULL != localtime_r(timer, &lct)) { back = dk4time_convert_to_text_c8(dptr, szdptr, &lct, erp); } else { dk4error_set_simple_error_code(erp, DK4_E_BUG); } return back; #else dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED); return 0; #endif } static int dk4fileinfo_c8_nonwin_timestamp( char *dptr, size_t szdptr, const dk4_stat_t *stb, int chtime, dk4_er_t *erp ) { int back = 0; switch (chtime) { case DK4_FILE_INFO_TIME_ACCESS: { back = dk4fileinfo_c8_stat_time_timestamp( dptr, szdptr, &(stb->st_atime), erp ); } break; case DK4_FILE_INFO_TIME_CREATE: { back = dk4fileinfo_c8_stat_time_timestamp( dptr, szdptr, &(stb->st_ctime), erp ); } break; default: { back = dk4fileinfo_c8_stat_time_timestamp( dptr, szdptr, &(stb->st_mtime), erp ); } break; } return back; } /* ----- non-Windows ----- */ #endif int dk4fileinfo_timestamp_c8( char *dptr, size_t szdptr, const dk4_file_info_t *fi, int chfile, int chtime, dk4_er_t *erp ) { int back = 0; if ((NULL != dptr) && (NULL != fi) && (0 < szdptr)) { switch (chfile) { case DK4_FILE_INFO_CONTENTS_DATA_LINK: { if (0 != (DK4_FILE_INFO_CONTENTS_DATA_LINK & (fi->contents))) { #if DK4_ON_WINDOWS back = dk4fileinfo_c8_win_timestamp( dptr, szdptr, &(fi->linfo), chtime, erp ); #else back = dk4fileinfo_c8_nonwin_timestamp( dptr, szdptr, &(fi->lstb), chtime, erp ); #endif } else { dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND); } } break; default: { if (0 != (DK4_FILE_INFO_CONTENTS_DATA_TARGET & (fi->contents))) { #if DK4_ON_WINDOWS back = dk4fileinfo_c8_win_timestamp( dptr, szdptr, &(fi->tinfo), chtime, erp ); #else back = dk4fileinfo_c8_nonwin_timestamp( dptr, szdptr, &(fi->tstb), chtime, erp ); #endif } else { dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND); } } break; } } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; } int dk4fileinfo_type_attributes_c8( char *dptr, size_t szdptr, dk4_file_info_t *fi, dk4_er_t *erp ) { size_t i; int back = 0; if ((NULL != dptr) && (NULL != fi) && (0 < szdptr)) { DK4_MEMRES(dptr, szdptr); #if DK4_ON_WINDOWS if (14 < szdptr) { back = 1; for (i = 0; i < 12; i++) { dptr[i] = '-'; } /* 0 reparse point or symlink */ if (0 != (DK4_FILE_INFO_CONTENTS_DATA_LINK & (fi->contents))) { if (0 != (FILE_ATTRIBUTE_REPARSE_POINT & (fi->fattr))) { dptr[0] = 'r'; if (IO_REPARSE_TAG_MOUNT_POINT == fi->rppnt) { dptr[0] = 'm'; } else { if (IO_REPARSE_TAG_SYMLINK == fi->rppnt) { dptr[0] = 'l'; if (0 != (DK4_FILE_INFO_CONTENTS_DATA_TARGET & (fi->contents))) { if ( (fi->linfo).dwVolumeSerialNumber != (fi->tinfo).dwVolumeSerialNumber ) { dptr[0] = 'L'; } } else { dptr[0] = '!'; } } else { if (IO_REPARSE_TAG_WIM == fi->rppnt) { dptr[0] = 'w'; } else { if (IO_REPARSE_TAG_SIS == fi->rppnt) { dptr[0] = 's'; } else { #ifdef IO_REPARSE_TAG_NFS /* Not available in VS2008+PSDK7 */ if (IO_REPARSE_TAG_NFS == fi->rppnt) { dptr[0] = 'n'; } else { #endif if (IO_REPARSE_TAG_CSV == fi->rppnt) { dptr[0] = 'c'; } else { if (IO_REPARSE_TAG_DFS == fi->rppnt) { dptr[0] = 'd'; } else { if (IO_REPARSE_TAG_DFSR == fi->rppnt) { dptr[0] = 'f'; } else { #ifdef IO_REPARSE_TAG_DEDUP /* Not available in VS2008+PSDK7 */ if (IO_REPARSE_TAG_DEDUP == fi->rppnt) { dptr[0] = 'u'; } else { #endif if (IO_REPARSE_TAG_HSM == fi->rppnt) { dptr[0] = 'h'; } else { if (IO_REPARSE_TAG_HSM2 == fi->rppnt) { dptr[0] = '2'; } } #ifdef IO_REPARSE_TAG_DEDUP } #endif } } } #ifdef IO_REPARSE_TAG_NFS } #endif } } } } } } /* 1 file type */ if (0 != (FILE_ATTRIBUTE_DIRECTORY & fi->fattr)) { dptr[1] = 'd'; } else { if (0 != (FILE_ATTRIBUTE_DEVICE & fi->fattr)) { dptr[1] = 'b'; } } /* 2 read-only */ if (0 != (FILE_ATTRIBUTE_READONLY & fi->fattr)) { dptr[2] = 'R'; } /* 3 system file */ if (0 != (FILE_ATTRIBUTE_SYSTEM & fi->fattr)) { dptr[3] = 'S'; } /* 4 hidden */ if (0 != (FILE_ATTRIBUTE_HIDDEN & fi->fattr)) { dptr[4] = 'H'; } /* 5 not indexed */ if (0 != (FILE_ATTRIBUTE_NOT_CONTENT_INDEXED & fi->fattr)) { dptr[5] = 'I'; } /* 6 compressed */ if (0 != (FILE_ATTRIBUTE_COMPRESSED & fi->fattr)) { dptr[6] = 'C'; } /* 7 encrypted */ if (0 != (FILE_ATTRIBUTE_ENCRYPTED & fi->fattr)) { dptr[7] = 'E'; } /* 8 offline */ if (0 != (FILE_ATTRIBUTE_OFFLINE & fi->fattr)) { dptr[8] = 'O'; } /* 9 sparse file */ if (0 != (FILE_ATTRIBUTE_SPARSE_FILE & fi->fattr)) { dptr[9] = 'P'; } /* 10 temporary file */ if (0 != (FILE_ATTRIBUTE_TEMPORARY & fi->fattr)) { dptr[10] = 'T'; } /* 11 virtual file */ if (0 != (FILE_ATTRIBUTE_VIRTUAL & fi->fattr)) { dptr[11] = 'V'; } } else { #line 372 "dk4fileig8.ctr" dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } #else if (12 < szdptr) { back = 1; for (i = 0; i < 11; i++) { dptr[i] = '-'; } /* 0 symlink */ if (0 != (DK4_FILE_INFO_CONTENTS_DATA_LINK & (fi->contents))) { #if defined(S_IFMT) && defined(S_IFLNK) if (S_IFLNK == (S_IFMT & ((fi->lstb).st_mode))) { if (0 != (DK4_FILE_INFO_CONTENTS_DATA_TARGET & (fi->contents))) { if ((fi->tstb).st_dev == (fi->lstb).st_dev) { dptr[0] = 'l'; } else { dptr[0] = 'L'; } } else { dptr[0] = '!'; } } #endif } /* 1 file type */ dptr[1] = '?'; if (0 != (DK4_FILE_INFO_CONTENTS_DATA_TARGET & (fi->contents))) { switch (S_IFMT & ((fi->tstb).st_mode)) { case S_IFIFO: { dptr[1] = 'p'; } break; case S_IFCHR: { dptr[1] = 'c'; } break; case S_IFDIR: { dptr[1] = 'd'; } break; case S_IFBLK: { dptr[1] = 'b'; } break; case S_IFREG: { dptr[1] = '-'; } break; case S_IFSOCK: { dptr[1] = 's'; } break; #ifdef S_IFMPC case S_IFMPC: { dptr[1] = 'C'; } break; #endif #ifdef S_IFNAM case S_IFNAM: { dptr[1] = 'O'; } break; #endif #ifdef S_INSEM case S_INSEM: { dptr[1] = 'N'; } break; #endif #ifdef S_INSHD case S_INSHD: { dptr[1] = 'M'; } break; #endif #ifdef S_IFMPB case S_IFMPB: { dptr[1] = 'B'; } break; #endif #ifdef S_IFCMP case S_IFCMP: { dptr[1] = 'v'; } break; #endif #ifdef S_IFNWK case S_IFNWK: { dptr[1] = 'n'; } break; #endif #ifdef S_IFSHAD case S_IFSHAD: { dptr[1] = 'a'; } break; #endif #ifdef S_IFDOOR case S_IFDOOR: { dptr[1] = 'D'; } break; #endif #ifdef S_IFWHT case S_IFWHT: { dptr[1] = 'w'; } break; #endif } /* 2 user read */ if (0 != (S_IRUSR & ((fi->tstb).st_mode))) { dptr[2] = 'r'; } /* 3 user write */ if (0 != (S_IWUSR & ((fi->tstb).st_mode))) { dptr[3] = 'w'; } /* 4 user execute */ if (0 != (S_IXUSR & ((fi->tstb).st_mode))) { dptr[4] = 'x'; } /* 4 user sticky */ if (0 != (S_ISUID & ((fi->tstb).st_mode))) { dptr[4] = (('x' == dptr[4]) ? ('s') : ('S')); } /* 5 group read */ if (0 != (S_IRGRP & ((fi->tstb).st_mode))) { dptr[5] = 'r'; } /* 6 group write */ if (0 != (S_IWGRP & ((fi->tstb).st_mode))) { dptr[6] = 'w'; } /* 7 group execute */ if (0 != (S_IXGRP & ((fi->tstb).st_mode))) { dptr[7] = 'x'; } /* 7 group sticky */ if (0 != (S_ISGID & ((fi->tstb).st_mode))) { dptr[7] = (('x' == dptr[7]) ? ('s') : ('S')); } /* 8 other read */ if (0 != (S_IROTH & ((fi->tstb).st_mode))) { dptr[8] = 'r'; } /* 9 other write */ if (0 != (S_IWOTH & ((fi->tstb).st_mode))) { dptr[9] = 'w'; } /* 10 other execute */ if (0 != (S_IXOTH & ((fi->tstb).st_mode))) { dptr[10] = 'x'; } /* 10 dir sticky */ if (0 != (S_ISVTX & ((fi->tstb).st_mode))) { dptr[10] = (('x' == dptr[10]) ? ('t') : ('T')); } } else { dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND); } } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } #endif } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; }