src/nvim/fileio.c
/*
 * Convert a file with the 'charconvert' expression.
 * This closes the file which is to be read, converts it and opens the
 * resulting file for reading.
 * Returns name of the resulting converted file (the caller should delete it
 * after reading it).
 * Returns NULL if the conversion failed ("*fdp" is not set) .
 */
Convert a file with the 'charconvert' expression.
This closes the file which is to be read, converts it and opens the
resulting file for reading.
Returns name of the resulting converted file (the caller should delete it
after reading it).
Returns NULL if the conversion failed ("*fdp" is not set) .
Convert a file with the ' charconvert ' expression . This closes the file which is to be read converts it and opens the resulting file for reading . Returns name of the resulting converted file ( the caller should delete it after reading it ) . Returns NULL if the conversion failed ( " * fdp " is not set ) .
static char_u *
readfile_charconvert (
    char_u *fname,             
    char_u *fenc,              
    int *fdp               
)
{
  char_u      *tmpname;
  char_u      *errmsg = NULL;
  tmpname = vim_tempname();
  if (tmpname == NULL)
    errmsg = (char_u *)_("Can't find temp file for conversion");
  else {
    close(*fdp);                
    *fdp = -1;
    if (eval_charconvert((char *) fenc, enc_utf8 ? "utf-8" : (char *) p_enc,
                         (char *) fname, (char *) tmpname) == FAIL) {
      errmsg = (char_u *)_("Conversion with 'charconvert' failed");
    }
    if (errmsg == NULL && (*fdp = os_open((char *)tmpname, O_RDONLY, 0)) < 0) {
      errmsg = (char_u *)_("can't read output of 'charconvert'");
    }
  }
  if (errmsg != NULL) {
    MSG(errmsg);
    if (tmpname != NULL) {
      os_remove((char *)tmpname);  
      XFREE_CLEAR(tmpname);
    }
  }
  if (*fdp < 0) {
    *fdp = os_open((char *)fname, O_RDONLY, 0);
  }
  return tmpname;
}
static char_u * readfile_charconvert ( char_u * fname , char_u * fenc , int * fdp ) { char_u * tmpname ; char_u * errmsg = NULL ; tmpname = vim_tempname ( ) ; if ( tmpname == NULL ) errmsg = ( char_u * ) _ ( " " ) ; else { close ( * fdp ) ; * fdp = -1 ; if ( eval_charconvert ( ( char * ) fenc , enc_utf8 ? " " : ( char * ) p_enc , ( char * ) fname , ( char * ) tmpname ) == FAIL ) { errmsg = ( char_u * ) _ ( " " ) ; } if ( errmsg == NULL && ( * fdp = os_open ( ( char * ) tmpname , O_RDONLY , 0 ) ) < 0 ) { errmsg = ( char_u * ) _ ( " " ) ; } } if ( errmsg != NULL ) { MSG ( errmsg ) ; if ( tmpname != NULL ) { os_remove ( ( char * ) tmpname ) ; XFREE_CLEAR ( tmpname ) ; } } if ( * fdp < 0 ) { * fdp = os_open ( ( char * ) fname , O_RDONLY , 0 ) ; } return tmpname ; }
Convert a file with the 'charconvert' expression.
Convert a file with the ' charconvert ' expression .
/* name of input file */ /* converted from */ /* in/out: file descriptor of file */ /* close the input file, ignore errors */ /* Don't use emsg(), it breaks mappings, the retry with
     * another type of conversion might still work. */ // delete converted file /* If the input file is closed, open it (caller should check for error). */