mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
mf_open(): never fails (except for OOM)
This commit is contained in:
@@ -76,8 +76,7 @@
|
|||||||
|
|
||||||
/// @param flags Flags for open() call.
|
/// @param flags Flags for open() call.
|
||||||
///
|
///
|
||||||
/// @return - The open memory file, on success.
|
/// @return The open memory file.
|
||||||
/// - NULL, on failure.
|
|
||||||
memfile_T *mf_open(char_u *fname, int flags)
|
memfile_T *mf_open(char_u *fname, int flags)
|
||||||
{
|
{
|
||||||
memfile_T *mfp = xmalloc(sizeof(memfile_T));
|
memfile_T *mfp = xmalloc(sizeof(memfile_T));
|
||||||
|
@@ -246,7 +246,6 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
int ml_open(buf_T *buf)
|
int ml_open(buf_T *buf)
|
||||||
{
|
{
|
||||||
memfile_T *mfp;
|
|
||||||
bhdr_T *hp = NULL;
|
bhdr_T *hp = NULL;
|
||||||
ZERO_BL *b0p;
|
ZERO_BL *b0p;
|
||||||
PTR_BL *pp;
|
PTR_BL *pp;
|
||||||
@@ -275,12 +274,8 @@ int ml_open(buf_T *buf)
|
|||||||
buf->b_may_swap = false;
|
buf->b_may_swap = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Open the memfile. No swap file is created yet.
|
||||||
* Open the memfile. No swap file is created yet.
|
memfile_T *mfp = mf_open(NULL, 0);
|
||||||
*/
|
|
||||||
mfp = mf_open(NULL, 0);
|
|
||||||
if (mfp == NULL)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
buf->b_ml.ml_mfp = mfp;
|
buf->b_ml.ml_mfp = mfp;
|
||||||
buf->b_ml.ml_flags = ML_EMPTY;
|
buf->b_ml.ml_flags = ML_EMPTY;
|
||||||
@@ -364,11 +359,10 @@ int ml_open(buf_T *buf)
|
|||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (mfp != NULL) {
|
if (hp) {
|
||||||
if (hp)
|
mf_put(mfp, hp, false, false);
|
||||||
mf_put(mfp, hp, false, false);
|
|
||||||
mf_close(mfp, true); /* will also xfree(mfp->mf_fname) */
|
|
||||||
}
|
}
|
||||||
|
mf_close(mfp, true); // will also xfree(mfp->mf_fname)
|
||||||
buf->b_ml.ml_mfp = NULL;
|
buf->b_ml.ml_mfp = NULL;
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@@ -842,7 +836,7 @@ void ml_recover(void)
|
|||||||
mf_open() will consume "fname_used"! */
|
mf_open() will consume "fname_used"! */
|
||||||
mfp = mf_open(fname_used, O_RDONLY);
|
mfp = mf_open(fname_used, O_RDONLY);
|
||||||
fname_used = p;
|
fname_used = p;
|
||||||
if (mfp == NULL || mfp->mf_fd < 0) {
|
if (mfp->mf_fd < 0) {
|
||||||
EMSG2(_("E306: Cannot open %s"), fname_used);
|
EMSG2(_("E306: Cannot open %s"), fname_used);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
@@ -2488,7 +2488,7 @@ buf_T *open_spellbuf(void)
|
|||||||
buf->b_spell = true;
|
buf->b_spell = true;
|
||||||
buf->b_p_swf = true; // may create a swap file
|
buf->b_p_swf = true; // may create a swap file
|
||||||
if (ml_open(buf) == FAIL) {
|
if (ml_open(buf) == FAIL) {
|
||||||
ELOG("Error opening a new memline");
|
abort();
|
||||||
}
|
}
|
||||||
ml_open_file(buf); // create swap file now
|
ml_open_file(buf); // create swap file now
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user