Data Structures | Macros | Functions | Variables
fileio.c File Reference
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
#include "nvim/iconv.h"
#include "nvim/mbyte.h"
#include "nvim/memfile.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/os_defs.h"
#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/sha256.h"
#include "nvim/shada.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/types.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Data Structures

struct  bw_info


#define BUFSIZE   8192
#define SMBUFSIZE   256
#define HAS_BW_FLAGS
#define FIO_LATIN1   0x01
#define FIO_UTF8   0x02
#define FIO_UCS2   0x04
#define FIO_UCS4   0x08
#define FIO_UTF16   0x10
#define FIO_ENDIAN_L   0x80
#define FIO_NOCONVERT   0x2000
#define FIO_UCSBOM   0x4000
#define FIO_ALL   -1
#define CONV_RESTLEN   30
#define ICONV_MULT   8
#define SET_ERRMSG_NUM(num, msg)   errnum = num, errmsg = msg, errmsgarg = 0
#define SET_ERRMSG_ARG(msg, error)   errnum = NULL, errmsg = msg, errmsgarg = error
#define SET_ERRMSG(msg)   errnum = NULL, errmsg = msg, errmsgarg = 0


void filemess (buf_T *buf, char_u *name, char_u *s, int attr)
int readfile (char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, int flags)
void prep_exarg (exarg_T *eap, const buf_T *buf) FUNC_ATTR_NONNULL_ALL
void set_file_options (int set_options, exarg_T *eap)
void set_forced_fenc (exarg_T *eap)
char * new_file_message (void)
int buf_write (buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering)
void msg_add_lines (int insert_space, long lnum, off_T nchars)
void shorten_buf_fname (buf_T *buf, char_u *dirname, int force)
void shorten_fnames (int force)
 Shorten filenames for all buffers. More...
char * modname (const char *fname, const char *ext, bool prepend_dot) FUNC_ATTR_NONNULL_ARG(2)
bool vim_fgets (char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL
int get2c (FILE *fd)
int get3c (FILE *fd)
int get4c (FILE *fd)
time_t get8ctime (FILE *fd)
char * read_string (FILE *fd, size_t cnt)
bool put_bytes (FILE *fd, uintmax_t number, size_t len)
int put_time (FILE *fd, time_t time_)
int vim_rename (const char_u *from, const char_u *to) FUNC_ATTR_NONNULL_ALL
int check_timestamps (int focus)
int buf_check_timestamp (buf_T *buf) FUNC_ATTR_NONNULL_ALL
void buf_reload (buf_T *buf, int orig_mode)
void buf_store_file_info (buf_T *buf, FileInfo *file_info) FUNC_ATTR_NONNULL_ALL
void write_lnum_adjust (linenr_T offset)
int delete_recursive (const char *name)
void vim_deltempdir (void)
 Delete the temp directory and all files it contains. More...
char_uvim_gettempdir (void)
char_uvim_tempname (void)
bool match_file_pat (char_u *pattern, regprog_T **prog, char_u *fname, char_u *sfname, char_u *tail, int allow_dirs)
bool match_file_list (char_u *list, char_u *sfname, char_u *ffname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1
 if (regpat==NULL)
 xfree (regpat)
 if (match)
char_ufile_pat_to_reg_pat (const char_u *pat, const char_u *pat_end, char *allow_dirs, int no_bslash) FUNC_ATTR_NONNULL_ARG(1)


bool char_utail
char_uregpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, false)
char allow_dirs
bool match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs)
char_up = list
return false

Macro Definition Documentation


#define BUFSIZE   8192


#define CONV_RESTLEN   30


#define FIO_ALL   -1


#define FIO_ENDIAN_L   0x80


#define FIO_LATIN1   0x01


#define FIO_NOCONVERT   0x2000


#define FIO_UCS2   0x04


#define FIO_UCS4   0x08


#define FIO_UCSBOM   0x4000


#define FIO_UTF16   0x10


#define FIO_UTF8   0x02


#define HAS_BW_FLAGS


#define ICONV_MULT   8


#define SET_ERRMSG (   msg)    errnum = NULL, errmsg = msg, errmsgarg = 0


#define SET_ERRMSG_ARG (   msg,
)    errnum = NULL, errmsg = msg, errmsgarg = error


#define SET_ERRMSG_NUM (   num,
)    errnum = num, errmsg = msg, errmsgarg = 0


#define SMBUFSIZE   256



Function Documentation

◆ buf_check_timestamp()

int buf_check_timestamp ( buf_T buf)

◆ buf_reload()

void buf_reload ( buf_T buf,
int  orig_mode 

◆ buf_store_file_info()

void buf_store_file_info ( buf_T buf,
FileInfo file_info 

◆ buf_write()

int buf_write ( buf_T buf,
char_u fname,
char_u sfname,
linenr_T  start,
linenr_T  end,
exarg_T eap,
int  append,
int  forceit,
int  reset_changed,
int  filtering 

buf_write() - write to file "fname" lines "start" through "end"

We do our own buffering here because fwrite() is so slow.

If "forceit" is true, we don't care for errors when attempting backups. In case of an error everything possible is done to restore the original file. But when "forceit" is TRUE, we risk losing it.

When "reset_changed" is TRUE and "append" == FALSE and "start" == 1 and "end" == curbuf->b_ml.ml_line_count, reset curbuf->b_changed.

This function must NOT use NameBuff (because it's called by autowrite()).

eapfor forced 'ff' and 'fenc', can be NULL!
appendappend to the file
FAIL for failure, OK otherwise

◆ check_timestamps()

int check_timestamps ( int  focus)

Check if any not hidden buffer has been changed. Postpone the check if there are characters in the stuff buffer, a global command is being executed, a mapping is being executed or an autocommand is busy.

focuscalled for GUI focus event
TRUE if some message was written (screen should be redrawn and cursor positioned).

◆ delete_recursive()

int delete_recursive ( const char *  name)

Delete "name" and everything in it, recursively.

nameThe path which should be deleted.
0 for success, -1 if some file was not deleted.

◆ file_pat_to_reg_pat()

char_u* file_pat_to_reg_pat ( const char_u pat,
const char_u pat_end,
char *  allow_dirs,
int  no_bslash 

Convert the given pattern "pat" which has shell style wildcards in it, into a regular expression, and return the result in allocated memory. If there is a directory path separator to be matched, then TRUE is put in allow_dirs, otherwise FALSE is put there – webb. Handle backslashes before special characters, like "\*" and "\ ".

pat_endfirst char after pattern or NULL
allow_dirsResult passed back out in here
no_bslashDon't use a backward slash as pathsep
NULL on failure.

◆ filemess()

void filemess ( buf_T buf,
char_u name,
char_u s,
int  attr 

◆ get2c()

int get2c ( FILE *  fd)

Read 2 bytes from "fd" and turn them into an int, MSB first. Returns -1 when encountering EOF.

◆ get3c()

int get3c ( FILE *  fd)

Read 3 bytes from "fd" and turn them into an int, MSB first. Returns -1 when encountering EOF.

◆ get4c()

int get4c ( FILE *  fd)

Read 4 bytes from "fd" and turn them into an int, MSB first. Returns -1 when encountering EOF.

◆ get8ctime()

time_t get8ctime ( FILE *  fd)

Read 8 bytes from fd and turn them into a time_t, MSB first. Returns -1 when encountering EOF.

◆ if() [1/2]

if ( match  )

◆ if() [2/2]

if ( regpat  = NULL)

◆ match_file_list()

bool match_file_list ( char_u list,
char_u sfname,
char_u ffname 

Check if a file matches with a pattern in "list". "list" is a comma-separated list of patterns, like 'wildignore'. "sfname" is the short file name or NULL, "ffname" the long file name.

listlist of patterns to match
sfnameshort file name
ffnamefull file name
true if there was a match

◆ match_file_pat()

bool match_file_pat ( char_u pattern,
regprog_T **  prog,
char_u fname,
char_u sfname,
char_u tail,
int  allow_dirs 

Tries matching a filename with a "pattern" ("prog" is NULL), or use the precompiled regprog "prog" ("pattern" is NULL). That avoids calling vim_regcomp() often.

Used for autocommands and 'wildignore'.

patternpattern to match with
progpre-compiled regprog or NULL
fnamefull path of the file name
sfnameshort file name or NULL
tailtail of the path
allow_dirsAllow matching with dir
true if there is a match, false otherwise

◆ modname()

char* modname ( const char *  fname,
const char *  ext,
bool  prepend_dot 

Get new filename ended by given extension.

fnameThe original filename. If NULL, use current directory name and ext to compute new filename.
extThe extension to add to the filename. 4 chars max if prefixed with a dot, 3 otherwise.
prepend_dotIf true, prefix ext with a dot. Does nothing if ext already starts with a dot, or if fname is NULL.
[allocated] - A new filename, made up from:
  • fname + ext, if fname not NULL.
  • current dir + ext, if fname is NULL. Result is guaranteed to:
  • be ended by <ext>.
  • have a basename with at most BASENAMELEN chars: original basename is truncated if necessary.
  • be different than original: basename chars are replaced by "_" if necessary. If that can't be done because truncated value of original filename was made of all underscores, replace first "_" by "v".
  • NULL, if fname is NULL and there was a problem trying to get current directory.

◆ msg_add_lines()

void msg_add_lines ( int  insert_space,
long  lnum,
off_T  nchars 

◆ new_file_message()

char* new_file_message ( void  )

◆ prep_exarg()

void prep_exarg ( exarg_T eap,
const buf_T buf 

◆ put_bytes()

bool put_bytes ( FILE *  fd,
uintmax_t  number,
size_t  len 

Writes a number to file "fd", most significant bit first, in "len" bytes.

false in case of an error.

◆ put_time()

int put_time ( FILE *  fd,
time_t  time_ 

Writes time_t to file "fd" in 8 bytes.

FAIL when the write failed.

◆ read_string()

char* read_string ( FILE *  fd,
size_t  cnt 

Reads a string of length "cnt" from "fd" into allocated memory.

pointer to the string or NULL when unable to read that many bytes.

◆ readfile()

int readfile ( char_u fname,
char_u sfname,
linenr_T  from,
linenr_T  lines_to_skip,
linenr_T  lines_to_read,
exarg_T eap,
int  flags 

Read lines from file "fname" into the buffer after line "from".

  1. We allocate blocks with try_malloc, as big as possible.
  2. Each block is filled with characters from the file with a single read().
  3. The lines are inserted in the buffer with ml_append().

(caller must check that fname != NULL, unless READ_STDIN is used)

"lines_to_skip" is the number of lines that must be skipped "lines_to_read" is the number of lines that are appended When not recovering lines_to_skip is 0 and lines_to_read MAXLNUM.

flags: READ_NEW starting to edit a new buffer READ_FILTER reading filter output READ_STDIN read from stdin instead of a file READ_BUFFER read from curbuf instead of a file (converting after reading stdin) READ_DUMMY read into a dummy buffer (to check if file contents changed) READ_KEEP_UNDO don't clear undo info or read it from a file READ_FIFO read from fifo/socket instead of a file

eapcan be NULL!
FAIL for failure, NOTDONE for directory (failure), or OK

◆ set_file_options()

void set_file_options ( int  set_options,
exarg_T eap 

◆ set_forced_fenc()

void set_forced_fenc ( exarg_T eap)

◆ shorten_buf_fname()

void shorten_buf_fname ( buf_T buf,
char_u dirname,
int  force 

Shorten filename of a buffer. When "force" is TRUE: Use full path from now on for files currently being edited, both for file name and swap file name. Try to shorten the file names a bit, if safe to do so. When "force" is FALSE: Only try to shorten absolute file names. For buffers that have buftype "nofile" or "scratch": never change the file name.

◆ shorten_fnames()

void shorten_fnames ( int  force)

Shorten filenames for all buffers.

◆ vim_deltempdir()

void vim_deltempdir ( void  )

Delete the temp directory and all files it contains.

◆ vim_fgets()

bool vim_fgets ( char_u buf,
int  size,
FILE *  fp 

Like fgets(), but if the file line is too long, it is truncated and the rest of the line is thrown away.

[out]bufbuffer to fill
sizesize of the buffer
fpfile to read from
true for EOF or error

◆ vim_gettempdir()

char_u* vim_gettempdir ( void  )

Get the name of temp directory. This directory would be created on the first call to this function.

◆ vim_rename()

int vim_rename ( const char_u from,
const char_u to 

os_rename() only works if both files are on the same file system, this function will (attempts to?) copy the file across if rename fails – webb

-1 for failure, 0 for success

◆ vim_tempname()

char_u* vim_tempname ( void  )

Return a unique name that can be used for a temp file.

The temp file is NOT created.
pointer to the temp file name or NULL if Neovim can't create temporary directory for its own temporary files.

◆ write_lnum_adjust()

void write_lnum_adjust ( linenr_T  offset)

◆ xfree()

xfree ( regpat  )

Variable Documentation

◆ allow_dirs

char allow_dirs

◆ false

return false

◆ match

match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs)

◆ p

while p = list

◆ regpat

◆ tail

Initial value:
char_u buf[100]
char *const buf
Definition: encode.c:238
unsigned char char_u
Definition: types.h:12