1 /* datei.h 2 * This file belongs to Worker, a file manager for UN*X/X11. 3 * Copyright (C) 2001-2020 Ralf Hoffmann. 4 * You can contact me at: ralf@boomerangsworld.de 5 * or http://www.boomerangsworld.de/worker 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 #ifndef DATEI_H 23 #define DATEI_H 24 25 #include "wdefines.h" 26 #include <string> 27 28 class AWidth; 29 30 class CopyfileProgressCallback 31 { 32 public: 33 virtual ~CopyfileProgressCallback() = 0; 34 35 typedef enum { 36 COPYFILE_CONTINUE, 37 COPYFILE_ABORT 38 } callback_return_t; 39 40 virtual callback_return_t progress_callback( loff_t current_bytes, 41 loff_t total_bytes ) = 0; 42 }; 43 44 class Datei 45 { 46 public: 47 Datei(); 48 ~Datei(); 49 Datei( const Datei &other ); 50 Datei &operator=( const Datei &other ); 51 52 int open( const char *name, const char *mode ); 53 int close(); 54 int putUChar(unsigned char value); 55 int putUShort(unsigned short int value); 56 int putInt(int); 57 int putULong(unsigned long value); 58 int putString( const char *str1 ); 59 unsigned char getUChar(); 60 int getCharAsInt(); 61 unsigned short int getUShort(); 62 int getInt(); 63 unsigned long getULong(); 64 char *getString(int count); 65 int getString(char *,int count); 66 void seek(long offset,int mode); 67 int overreadChunk(); 68 long errors(); 69 int putStringExt(const char *format,const char *str); 70 int putLine( const char *str ); 71 char *getLine(); 72 bool isEOF(); 73 74 static int getIntSize(); 75 static int getUCharSize(); 76 static int getUShortSize(); 77 static int getULongSize(); 78 static bool fileExists(const char*); 79 typedef enum {D_FE_NOFILE,D_FE_FILE,D_FE_DIR,D_FE_LINK} d_fe_t; 80 static d_fe_t fileExistsExt(const char*); 81 static d_fe_t lfileExistsExt(const char*); 82 static char *getFilenameFromPath(const char*); 83 static char *getNameWithoutExt(const char*); 84 static char *createTMPName( const char *infix = NULL, 85 const char *suffix = NULL ); 86 static std::string createTMPHardlink( const std::string &name ); 87 static char *shrinkFilename( const char *str, int maxlength, AWidth &lencalc ); 88 static loff_t fileSize( const char * ); 89 static char *getRelativePath( const char *source, const char *destdir, bool use_realpath ); 90 91 /** 92 * the same as getRelativePath, but it will test both source and 93 * realpath(source) and return the shorter relative path. 94 */ 95 static char *getRelativePathExt( const char *source, 96 const char *destdir, 97 bool use_realpath ); 98 99 static int copyfile( const char *dest, const char *source, 100 CopyfileProgressCallback *progress_callback = NULL ); 101 102 void configPutPair( const char *id, const char *info ); 103 void configPutPairNum( const char *id, int num ); 104 void configPutPairNum( const char *id, int num1, int num2 ); 105 void configPutPairString( const char *id, const char *str, bool escape_newlines = false); 106 void configPutPairBool( const char *id, bool val ); 107 void configPutInfo( const char *str, bool semicolon ); 108 void configPutString( const char *str, bool semicolon, bool escape_newlines = false ); 109 void configOpenSection( const char *sectioname ); 110 void configCloseSection(); 111 112 ssize_t read( char *buffer, size_t len ); 113 private: 114 int fd; 115 long error; 116 int putCharacter( int c ); 117 int getCharacter(); 118 bool iseof; 119 120 int sectiondepth; 121 }; 122 123 int getOwnerStringLen(uid_t,gid_t); 124 char* getOwnerString(uid_t,gid_t); 125 126 #endif 127 128 /* Local Variables: */ 129 /* mode:c++ */ 130 /* End: */ 131