Drizzled Public API Documentation

my_sys.h
00001 /* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 MySQL
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #ifdef __cplusplus
00024 # include <cstdio>
00025 #else
00026 # include <stdio.h>
00027 #endif
00028 
00029 #include <errno.h>
00030 #include <sys/types.h>
00031 
00032 #include <drizzled/definitions.h>
00033 #include <drizzled/internal/my_pthread.h>
00034 
00035 #include <stdarg.h>
00036 
00037 #ifndef errno       /* did we already get it? */
00038 #ifdef HAVE_ERRNO_AS_DEFINE
00039 #include <errno.h>      /* errno is a define */
00040 #else
00041 extern int errno;     /* declare errno */
00042 #endif
00043 #endif          /* #ifndef errno */
00044 
00045 #ifdef HAVE_SYS_MMAN_H 
00046 #include <sys/mman.h>
00047 #endif
00048 
00049 #include <drizzled/qsort_cmp.h>
00050 
00051 #include <drizzled/visibility.h>
00052 
00053 namespace drizzled {
00054 namespace internal {
00055 
00056 #ifndef MAP_NOSYNC
00057 #define MAP_NOSYNC      0
00058 #endif
00059 #ifndef MAP_NORESERVE
00060 #define MAP_NORESERVE 0         /* For irix and AIX */
00061 #endif
00062 
00063 /*
00064   EDQUOT is used only in 3 C files only in mysys/. If it does not exist on
00065   system, we set it to some value which can never happen.
00066 */
00067 #ifndef EDQUOT
00068 #define EDQUOT (-1)
00069 #endif
00070 
00071   /* General bitmaps for my_func's */
00072 #define MY_FFNF   1 /* Fatal if file not found */
00073 #define MY_FNABP  2 /* Fatal if not all bytes read/writen */
00074 #define MY_NABP   4 /* Error if not all bytes read/writen */
00075 #define MY_FAE    8 /* Fatal if any error */
00076 #define MY_WME    16  /* Write message on error */
00077 #define MY_WAIT_IF_FULL 32  /* Wait and try again if disk full error */
00078 #define MY_IGNORE_BADFD 32      /* my_sync: ignore 'bad descriptor' errors */
00079 #define MY_SYNC_DIR     1024    /* my_create/delete/rename: sync directory */
00080 #define MY_FULL_IO     512      /* For my_read - loop intil I/O is complete */
00081 #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
00082 #define MY_LINK_WARNING 32  /* my_redel() gives warning if links */
00083 #define MY_COPYTIME 64  /* my_redel() copys time */
00084 #define MY_DELETE_OLD 256 /* my_create_with_symlink() */
00085 #define MY_HOLD_ORIGINAL_MODES 128  /* my_copy() holds to file modes */
00086 #define MY_DONT_WAIT  64  /* my_lock() don't wait if can't lock */
00087 #define MY_DONT_OVERWRITE_FILE 1024 /* my_copy: Don't overwrite file */
00088 #define MY_THREADSAFE 2048      /* my_seek(): lock fd mutex */
00089 
00090 #define ME_OLDWIN 2 /* Use old window */
00091 #define ME_BELL   4 /* Ring bell then printing message */
00092 #define ME_WAITTANG 32  /* Wait for a user action  */
00093 #define ME_NOREFRESH  64  /* Dont refresh screen */
00094 #define ME_NOINPUT  128 /* Dont use the input libary */
00095 
00096   /* Bits in last argument to fn_format */
00097 #define MY_REPLACE_DIR    1 /* replace dir in name with 'dir' */
00098 #define MY_REPLACE_EXT    2 /* replace extension with 'ext' */
00099 #define MY_UNPACK_FILENAME  4 /* Unpack name (~ -> home) */
00100 #define MY_RESOLVE_SYMLINKS 16  /* Resolve all symbolic links */
00101 #define MY_RETURN_REAL_PATH 32  /* return full path for file */
00102 #define MY_SAFE_PATH    64  /* Return NULL if too long path */
00103 #define MY_RELATIVE_PATH  128 /* name is relative to 'dir' */
00104 #define MY_APPEND_EXT           256     /* add 'ext' as additional extension*/
00105 
00106 typedef uint64_t my_off_t;
00107 
00108 extern char *home_dir;      /* Home directory for user */
00109 extern const char *my_progname;   /* program-name (printed in errors) */
00110 
00111 extern DRIZZLED_API int my_umask,   /* Default creation mask  */
00112      my_umask_dir;
00113 extern bool my_use_symdir;
00114 
00115 extern uint32_t my_default_record_cache_size;
00116 extern bool my_disable_symlinks;
00117 extern const char wild_many, wild_one, wild_prefix;
00118 extern const char *charsets_dir;
00119 
00120 extern bool timed_mutexes;
00121 
00122 enum cache_type
00123 {
00124   TYPE_NOT_SET= 0,
00125   READ_CACHE,
00126   WRITE_CACHE,
00127   READ_FIFO,
00128   READ_NET,
00129   WRITE_NET
00130 };
00131 
00132 typedef struct record_cache /* Used when cacheing records */
00133 {
00134 public:
00135   int file;
00136   int rc_seek,error,inited;
00137   uint  rc_length,read_length,reclength;
00138   my_off_t rc_record_pos,end_of_file;
00139   unsigned char *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
00140   enum cache_type type;
00141 
00142   record_cache():
00143     file(0),
00144     rc_seek(0),
00145     error(0),
00146     inited(0),
00147     rc_length(0),
00148     read_length(0),
00149     reclength(0),
00150     rc_record_pos(0),
00151     end_of_file(0),
00152     rc_buff(NULL),
00153     rc_buff2(NULL),
00154     rc_pos(NULL),
00155     rc_end(NULL),
00156     rc_request_pos(NULL)
00157   {}
00158 
00159 } RECORD_CACHE;
00160 
00161 /* Prototypes for mysys and my_func functions */
00162 
00163 extern int my_copy(const char *from,const char *to,myf MyFlags);
00164 DRIZZLED_API int my_delete(const char *name,myf MyFlags);
00165 DRIZZLED_API int my_open(const char *FileName,int Flags,myf MyFlags);
00166 extern int my_register_filename(int fd, const char *FileName, uint32_t error_message_number, myf MyFlags);
00167 DRIZZLED_API int my_create(const char *FileName,int CreateFlags, int AccessFlags, myf MyFlags);
00168 DRIZZLED_API int my_close(int Filedes,myf MyFlags);
00169 extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
00170 extern int my_realpath(char *to, const char *filename, myf MyFlags);
00171 extern int my_create_with_symlink(const char *linkname, const char *filename,
00172                                   int createflags, int access_flags, myf MyFlags);
00173 DRIZZLED_API int my_delete_with_symlink(const char *name, myf MyFlags);
00174 extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
00175 DRIZZLED_API size_t my_read(int Filedes,unsigned char *Buffer,size_t Count,myf MyFlags);
00176 DRIZZLED_API int my_rename(const char *from, const char *to,myf MyFlags);
00177 DRIZZLED_API size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags);
00178 
00179 extern int check_if_legal_tablename(const char *path);
00180 
00181 DRIZZLED_API int my_sync(int fd, myf my_flags);
00182 extern int my_sync_dir(const char *dir_name, myf my_flags);
00183 extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
00184 extern void my_init();
00185 extern void my_end();
00186 extern int my_redel(const char *from, const char *to, int MyFlags);
00187 extern int my_copystat(const char *from, const char *to, int MyFlags);
00188 
00189 extern void my_remember_signal(int signal_number,void (*func)(int));
00190 extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
00191 extern size_t dirname_length(const char *name);
00192 #define base_name(A) (A+dirname_length(A))
00193 bool test_if_hard_path(const char *dir_name);
00194 
00195 extern char *convert_dirname(char *to, const char *from, const char *from_end);
00196 extern char * fn_ext(const char *name);
00197 extern char * fn_same(char * toname,const char *name,int flag);
00198 DRIZZLED_API char * fn_format(char * to,const char *name,const char *dir, const char *form, uint32_t flag);
00199 extern size_t unpack_dirname(char * to,const char *from);
00200 extern size_t unpack_filename(char * to,const char *from);
00201 extern char * intern_filename(char * to,const char *from);
00202 extern int pack_filename(char * to, const char *name, size_t max_length);
00203 extern char * my_load_path(char * to, const char *path, const char *own_path_prefix);
00204 extern void my_string_ptr_sort(unsigned char *base,uint32_t items,size_t size);
00205 extern void radixsort_for_str_ptr(unsigned char* base[], uint32_t number_of_elements, size_t size_of_element,unsigned char *buffer[]);
00206 extern void my_qsort(void *base_ptr, size_t total_elems, size_t size, qsort_cmp cmp);
00207 extern void my_qsort2(void *base_ptr, size_t total_elems, size_t size, qsort2_cmp cmp, void *cmp_argument);
00208 extern qsort2_cmp get_ptr_compare(size_t);
00209 DRIZZLED_API void my_store_ptr(unsigned char *buff, size_t pack_length, my_off_t pos);
00210 DRIZZLED_API my_off_t my_get_ptr(unsigned char *ptr, size_t pack_length);
00211 int create_temp_file(char *to, const char *dir, const char *pfx, myf MyFlags);
00212 
00213 } /* namespace internal */
00214 } /* namespace drizzled */