neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

os_defs.h (3212B)


      1 #pragma once
      2 
      3 #include <ctype.h>
      4 #include <stdio.h>
      5 #include <stdlib.h>
      6 #include <sys/stat.h>
      7 #include <sys/types.h>
      8 
      9 #include "auto/config.h"
     10 
     11 // Note: Some systems need both string.h and strings.h (Savage).
     12 #include <string.h>
     13 #ifdef HAVE_STRINGS_H
     14 # include <strings.h>  // IWYU pragma: export
     15 #endif
     16 
     17 #ifdef MSWIN
     18 # include "nvim/os/win_defs.h"
     19 #else
     20 # include "nvim/os/unix_defs.h"
     21 #endif
     22 
     23 #ifdef BACKSLASH_IN_FILENAME
     24 # define BACKSLASH_IN_FILENAME_BOOL true
     25 #else
     26 # define BACKSLASH_IN_FILENAME_BOOL false
     27 #endif
     28 
     29 #if !defined(NAME_MAX) && defined(_XOPEN_NAME_MAX)
     30 # define NAME_MAX _XOPEN_NAME_MAX
     31 #endif
     32 
     33 #define BASENAMELEN (NAME_MAX - 5)
     34 
     35 // Use the system path length if it makes sense.
     36 #define DEFAULT_MAXPATHL 4096
     37 #if defined(PATH_MAX) && (PATH_MAX > DEFAULT_MAXPATHL)
     38 # define MAXPATHL PATH_MAX
     39 #else
     40 # define MAXPATHL DEFAULT_MAXPATHL
     41 #endif
     42 
     43 // Command-processing buffer. Use large buffers for all platforms.
     44 #define CMDBUFFSIZE 1024
     45 
     46 #define ROOT_UID 0
     47 
     48 /// Converts libuv error (negative int) to error description string.
     49 #define os_strerror uv_strerror
     50 
     51 /// Converts system error code to libuv error code.
     52 #define os_translate_sys_error uv_translate_sys_error
     53 
     54 #ifdef MSWIN
     55 # define os_strtok strtok_s
     56 #else
     57 # define os_strtok strtok_r
     58 #endif
     59 
     60 // stat macros
     61 #ifndef S_ISDIR
     62 # ifdef S_IFDIR
     63 #  define S_ISDIR(m)    (((m)& S_IFMT) == S_IFDIR)
     64 # else
     65 #  define S_ISDIR(m)    0
     66 # endif
     67 #endif
     68 #ifndef S_ISREG
     69 # ifdef S_IFREG
     70 #  define S_ISREG(m)    (((m)& S_IFMT) == S_IFREG)
     71 # else
     72 #  define S_ISREG(m)    0
     73 # endif
     74 #endif
     75 #ifndef S_ISBLK
     76 # ifdef S_IFBLK
     77 #  define S_ISBLK(m)    (((m)& S_IFMT) == S_IFBLK)
     78 # else
     79 #  define S_ISBLK(m)    0
     80 # endif
     81 #endif
     82 #ifndef S_ISSOCK
     83 # ifdef S_IFSOCK
     84 #  define S_ISSOCK(m)   (((m)& S_IFMT) == S_IFSOCK)
     85 # else
     86 #  define S_ISSOCK(m)   0
     87 # endif
     88 #endif
     89 #ifndef S_ISFIFO
     90 # ifdef S_IFIFO
     91 #  define S_ISFIFO(m)   (((m)& S_IFMT) == S_IFIFO)
     92 # else
     93 #  define S_ISFIFO(m)   0
     94 # endif
     95 #endif
     96 #ifndef S_ISCHR
     97 # ifdef S_IFCHR
     98 #  define S_ISCHR(m)    (((m)& S_IFMT) == S_IFCHR)
     99 # else
    100 #  define S_ISCHR(m)    0
    101 # endif
    102 #endif
    103 #ifndef S_ISLNK
    104 # ifdef S_IFLNK
    105 #  define S_ISLNK(m)    (((m)& S_IFMT) == S_IFLNK)
    106 # else
    107 #  define S_ISLNK(m)    0
    108 # endif
    109 #endif
    110 
    111 // BSD is supposed to cover FreeBSD and similar systems.
    112 #if (defined(BSD) || defined(__FreeBSD_kernel__)) \
    113  && (defined(S_ISCHR) || defined(S_IFCHR))
    114 # define OPEN_CHR_FILES
    115 #endif
    116 
    117 // We use 64-bit file functions here, if available.  E.g. ftello() returns
    118 // off_t instead of long, which helps if long is 32 bit and off_t is 64 bit.
    119 // We assume that when fseeko() is available then ftello() is too.
    120 // Note that Windows has different function names.
    121 #if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__MINGW32__)
    122 typedef __int64 off_T;
    123 # ifdef __MINGW32__
    124 #  define vim_lseek lseek64
    125 #  define vim_fseek fseeko64
    126 #  define vim_ftell ftello64
    127 # else
    128 #  define vim_lseek _lseeki64
    129 #  define vim_fseek _fseeki64
    130 #  define vim_ftell _ftelli64
    131 # endif
    132 #else
    133 typedef off_t off_T;
    134 # ifdef HAVE_FSEEKO
    135 #  define vim_lseek lseek
    136 #  define vim_ftell ftello
    137 #  define vim_fseek fseeko
    138 # else
    139 #  define vim_lseek lseek
    140 #  define vim_ftell ftell
    141 #  define vim_fseek(a, b, c) fseek(a, (long)b, c)
    142 # endif
    143 #endif