/* 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: dk4filei.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 dk4filei.c The dk4filei module. */ #line 379 "dk4filei.ctr" #include "dk4filei.h" #ifndef DK4MEM_H_INCLUDED #include "dk4mem.h" #endif #ifndef DK4MAADU_H_INCLUDED #include "dk4maadu.h" #endif #line 393 "dk4filei.ctr" void dk4fileinfo_init(dk4_file_info_t *dptr) { if (NULL != dptr) { DK4_MEMRES(dptr, sizeof(dk4_file_info_t)); dptr->contents = 0; } } int dk4fileinfo_is_symlink(const dk4_file_info_t *dptr) { int back = 0; if (NULL != dptr) { if (0 != (DK4_FILE_INFO_CONTENTS_DATA_LINK & (dptr->contents))) { #if DK4_ON_WINDOWS if (0 != (FILE_ATTRIBUTE_REPARSE_POINT & (dptr->fattr))) { if (IO_REPARSE_TAG_MOUNT_POINT == dptr->rppnt) { back = 1; } if (IO_REPARSE_TAG_SYMLINK == dptr->rppnt) { back = 1; } } #else #if defined(S_IFMT) && defined (S_IFLNK) if (S_IFLNK == (S_IFMT & ((dptr->lstb).st_mode))) { back = 1; } #endif #endif } } return back; } #if DK4_ON_WINDOWS static int dk4fileinfo_copy_size( dk4_um_t *dptr, const BY_HANDLE_FILE_INFORMATION *bhfi, dk4_er_t *erp ) { dk4_er_t er; dk4_um_t val; int back = 0; #line 449 "dk4filei.ctr" dk4error_init(&er); #line 451 "dk4filei.ctr" #line 452 "dk4filei.ctr" if ((DWORD)0UL != bhfi->nFileSizeHigh) { val = dk4ma_um_add( dk4ma_um_mul( dk4ma_um_add( (dk4_um_t)0xFFFFFFFFUL, (dk4_um_t)1UL, &er ), (dk4_um_t)(bhfi->nFileSizeHigh), &er ), (dk4_um_t)(bhfi->nFileSizeLow), &er ); } else { val = (dk4_um_t)(bhfi->nFileSizeLow); } if (DK4_E_NONE == er.ec) { #line 470 "dk4filei.ctr" back = 1; *dptr = val; } else { #line 473 "dk4filei.ctr" dk4error_copy(erp, &er); } #line 476 "dk4filei.ctr" return back; } #else static int dk4fileinfo_copy_size( dk4_um_t *dptr, const dk4_stat_t *stb, dk4_er_t *erp ) { *dptr = (dk4_um_t)(stb->st_size); return 1; } #endif int dk4fileinfo_size( dk4_um_t *dptr, const dk4_file_info_t *fi, int ch, dk4_er_t *erp ) { dk4_er_t er; int back = 0; #line 504 "dk4filei.ctr" if ((NULL != dptr) && (NULL != fi)) { #line 505 "dk4filei.ctr" dk4error_init(&er); switch (ch) { case DK4_FILE_INFO_CONTENTS_DATA_LINK: { #line 509 "dk4filei.ctr" if (0 != ((fi->contents) & DK4_FILE_INFO_CONTENTS_DATA_LINK)) { #if DK4_ON_WINDOWS #line 512 "dk4filei.ctr" back = dk4fileinfo_copy_size(dptr, &(fi->linfo), &er); #else #line 515 "dk4filei.ctr" back = dk4fileinfo_copy_size(dptr, &(fi->lstb), &er); #endif } else { #line 518 "dk4filei.ctr" dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND); } } break; default: { #line 523 "dk4filei.ctr" if (0 != ((fi->contents) & DK4_FILE_INFO_CONTENTS_DATA_TARGET)) { #if DK4_ON_WINDOWS #line 526 "dk4filei.ctr" back = dk4fileinfo_copy_size(dptr, &(fi->tinfo), &er); #else #line 529 "dk4filei.ctr" back = dk4fileinfo_copy_size(dptr, &(fi->tstb), &er); #endif } else { #line 532 "dk4filei.ctr" dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND); } } break; } if (0 != back) { dk4error_copy(erp, &er); } } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } #line 542 "dk4filei.ctr" return back; } int dk4fileinfo_exists_and_is_regular(const dk4_file_info_t *fi, dk4_er_t *erp) { int back = 0; if (NULL != fi) { #if DK4_ON_WINDOWS if (0 != (DK4_FILE_INFO_CONTENTS_DATA_LINK & (fi->contents))) { if ((DWORD)0UL == (FILE_ATTRIBUTE_DIRECTORY & fi->fattr)) { if ((DWORD)0UL == (FILE_ATTRIBUTE_DEVICE & fi->fattr)) { back = 1; } } } #else if (0 != (DK4_FILE_INFO_CONTENTS_DATA_TARGET & (fi->contents))) { if (S_IFREG == (S_IFMT & ((fi->tstb).st_mode))) { back = 1; } } #endif } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; }