mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
Modified most functions in wutil.h/.cpp to use wcstring instead of wchar_t*, removing calls to c_str() while calling these functions in other files.
This commit is contained in:
parent
c0ed169fdc
commit
c9f4e91df8
9 changed files with 51 additions and 51 deletions
|
@ -20,11 +20,11 @@ static const int kAutoloadStalenessInterval = 15;
|
|||
file_access_attempt_t access_file(const wcstring &path, int mode) {
|
||||
file_access_attempt_t result = {0};
|
||||
struct stat statbuf;
|
||||
if (wstat(path.c_str(), &statbuf)) {
|
||||
if (wstat(path, &statbuf)) {
|
||||
result.error = errno;
|
||||
} else {
|
||||
result.mod_time = statbuf.st_mtime;
|
||||
if (waccess(path.c_str(), mode)) {
|
||||
if (waccess(path, mode)) {
|
||||
result.error = errno;
|
||||
} else {
|
||||
result.accessible = true;
|
||||
|
|
|
@ -1781,7 +1781,7 @@ bool string_prefixes_string(const wcstring &proposed_prefix, const wcstring &val
|
|||
return prefix_size <= value.size() && value.compare(0, prefix_size, proposed_prefix) == 0;
|
||||
}
|
||||
|
||||
int create_directory( const wchar_t *d )
|
||||
int create_directory( const wcstring &d )
|
||||
{
|
||||
int ok = 0;
|
||||
struct stat buf;
|
||||
|
@ -1805,7 +1805,7 @@ int create_directory( const wchar_t *d )
|
|||
if( errno == ENOENT )
|
||||
{
|
||||
wcstring dir = wdirname(d);
|
||||
if( !create_directory( dir.c_str() ) )
|
||||
if( !create_directory( dir ) )
|
||||
{
|
||||
if( !wmkdir( d, 0700 ) )
|
||||
{
|
||||
|
|
2
common.h
2
common.h
|
@ -559,7 +559,7 @@ void tokenize_variable_array( const wcstring &val, wcstring_list_t &out);
|
|||
|
||||
\return 0 if, at the time of function return the directory exists, -1 otherwise.
|
||||
*/
|
||||
int create_directory( const wchar_t *d );
|
||||
int create_directory( const wcstring &d );
|
||||
|
||||
/**
|
||||
Print a short message about how to file a bug report to stderr
|
||||
|
|
|
@ -128,7 +128,7 @@ static bool is_potential_path( const wcstring &cpath )
|
|||
must_be_dir = cleaned_path[cleaned_path.length()-1] == L'/';
|
||||
if( must_be_dir )
|
||||
{
|
||||
dir = wopendir( cleaned_path.c_str() );
|
||||
dir = wopendir( cleaned_path );
|
||||
res = !!dir;
|
||||
if( dir )
|
||||
{
|
||||
|
@ -144,12 +144,12 @@ static bool is_potential_path( const wcstring &cpath )
|
|||
{
|
||||
res = true;
|
||||
}
|
||||
else if( (dir = wopendir( dir_name.c_str() )) )
|
||||
else if( (dir = wopendir( dir_name)) )
|
||||
{
|
||||
wcstring ent;
|
||||
while (wreaddir(dir, ent))
|
||||
{
|
||||
if( wcsncmp( ent.c_str(), base_name.c_str(), base_name.length() ) == 0 )
|
||||
if( ent == base_name )
|
||||
{
|
||||
res = true;
|
||||
break;
|
||||
|
@ -802,7 +802,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
|
|||
if( slash_idx != wcstring::npos )
|
||||
{
|
||||
dir.resize(slash_idx);
|
||||
if( wstat( dir.c_str(), &buff ) == -1 )
|
||||
if( wstat( dir, &buff ) == -1 )
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||
if( error )
|
||||
|
|
10
history.cpp
10
history.cpp
|
@ -409,7 +409,7 @@ void history_t::load_old_if_needed(void)
|
|||
|
||||
if( ! filename.empty() )
|
||||
{
|
||||
if( ( fd = wopen( filename.c_str(), O_RDONLY ) ) > 0 )
|
||||
if( ( fd = wopen( filename, O_RDONLY ) ) > 0 )
|
||||
{
|
||||
off_t len = lseek( fd, 0, SEEK_END );
|
||||
if( len != (off_t)-1)
|
||||
|
@ -595,7 +595,7 @@ void history_t::save_internal()
|
|||
if( ! tmp_name.empty() )
|
||||
{
|
||||
FILE *out;
|
||||
if( (out=wfopen( tmp_name.c_str(), "w" ) ) )
|
||||
if( (out=wfopen( tmp_name, "w" ) ) )
|
||||
{
|
||||
|
||||
/* Load old */
|
||||
|
@ -639,7 +639,7 @@ void history_t::save_internal()
|
|||
else
|
||||
{
|
||||
wcstring new_name = history_filename(name, wcstring());
|
||||
wrename(tmp_name.c_str(), new_name.c_str());
|
||||
wrename(tmp_name, new_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -664,7 +664,7 @@ void history_t::clear(void) {
|
|||
old_item_offsets.clear();
|
||||
wcstring filename = history_filename(name, L"");
|
||||
if (! filename.empty())
|
||||
wunlink(filename.c_str());
|
||||
wunlink(filename);
|
||||
this->clear_file_state();
|
||||
|
||||
}
|
||||
|
@ -710,7 +710,7 @@ int file_detection_context_t::perform_file_detection(bool test_all) {
|
|||
if (path.at(0) != '/') {
|
||||
path.insert(0, working_directory);
|
||||
}
|
||||
path_is_valid = (0 == waccess(path.c_str(), F_OK));
|
||||
path_is_valid = (0 == waccess(path, F_OK));
|
||||
}
|
||||
|
||||
|
||||
|
|
4
path.cpp
4
path.cpp
|
@ -81,10 +81,10 @@ bool path_get_path_string(const wcstring &cmd_str, wcstring &output, const env_v
|
|||
if (path_len == 0) continue;
|
||||
|
||||
append_path_component(new_cmd, cmd_str);
|
||||
if( waccess( new_cmd.c_str(), X_OK )==0 )
|
||||
if( waccess( new_cmd, X_OK )==0 )
|
||||
{
|
||||
struct stat buff;
|
||||
if( wstat( new_cmd.c_str(), &buff )==-1 )
|
||||
if( wstat( new_cmd, &buff )==-1 )
|
||||
{
|
||||
if( errno != EACCES )
|
||||
{
|
||||
|
|
|
@ -593,7 +593,7 @@ static void wildcard_completion_allocate( std::vector<completion_t> &list,
|
|||
non-symlinks by first doing an lstat, and if the file is not a
|
||||
link we copy the results over to the regular stat buffer.
|
||||
*/
|
||||
if( ( lstat_res = lwstat( fullname.c_str(), &lbuf ) ) )
|
||||
if( ( lstat_res = lwstat( fullname, &lbuf ) ) )
|
||||
{
|
||||
sz=-1;
|
||||
stat_res = lstat_res;
|
||||
|
@ -603,7 +603,7 @@ static void wildcard_completion_allocate( std::vector<completion_t> &list,
|
|||
if( S_ISLNK(lbuf.st_mode))
|
||||
{
|
||||
|
||||
if( ( stat_res = wstat( fullname.c_str(), &buf ) ) )
|
||||
if( ( stat_res = wstat( fullname, &buf ) ) )
|
||||
{
|
||||
sz=-1;
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ static int wildcard_expand_internal( const wchar_t *wc,
|
|||
will be added in the next pass.
|
||||
*/
|
||||
struct stat buf;
|
||||
if( !wstat( long_name.c_str(), &buf ) )
|
||||
if( !wstat( long_name, &buf ) )
|
||||
{
|
||||
skip = S_ISDIR(buf.st_mode);
|
||||
}
|
||||
|
|
34
wutil.cpp
34
wutil.cpp
|
@ -118,25 +118,25 @@ wchar_t *wgetcwd( wchar_t *buff, size_t sz )
|
|||
return ret;
|
||||
}
|
||||
|
||||
int wchdir( const wchar_t * dir )
|
||||
int wchdir( const wcstring &dir )
|
||||
{
|
||||
cstring tmp = wcs2string(dir);
|
||||
return chdir( tmp.c_str() );
|
||||
}
|
||||
|
||||
FILE *wfopen(const wchar_t *path, const char *mode)
|
||||
FILE *wfopen(const wcstring &path, const char *mode)
|
||||
{
|
||||
cstring tmp = wcs2string(path);
|
||||
return fopen(tmp.c_str(), mode);
|
||||
}
|
||||
|
||||
FILE *wfreopen(const wchar_t *path, const char *mode, FILE *stream)
|
||||
FILE *wfreopen(const wcstring &path, const char *mode, FILE *stream)
|
||||
{
|
||||
cstring tmp = wcs2string(path);
|
||||
return freopen(tmp.c_str(), mode, stream);
|
||||
}
|
||||
|
||||
int wopen(const wchar_t *pathname, int flags, ...)
|
||||
int wopen(const wcstring &pathname, int flags, ...)
|
||||
{
|
||||
cstring tmp = wcs2string(pathname);
|
||||
int res=-1;
|
||||
|
@ -154,25 +154,25 @@ int wopen(const wchar_t *pathname, int flags, ...)
|
|||
return res;
|
||||
}
|
||||
|
||||
int wcreat(const wchar_t *pathname, mode_t mode)
|
||||
int wcreat(const wcstring &pathname, mode_t mode)
|
||||
{
|
||||
cstring tmp = wcs2string(pathname);
|
||||
return creat(tmp.c_str(), mode);
|
||||
}
|
||||
|
||||
DIR *wopendir(const wchar_t *name)
|
||||
DIR *wopendir(const wcstring &name)
|
||||
{
|
||||
cstring tmp = wcs2string(name);
|
||||
return opendir(tmp.c_str());
|
||||
}
|
||||
|
||||
int wstat(const wchar_t *file_name, struct stat *buf)
|
||||
int wstat(const wcstring &file_name, struct stat *buf)
|
||||
{
|
||||
cstring tmp = wcs2string(file_name);
|
||||
return stat(tmp.c_str(), buf);
|
||||
}
|
||||
|
||||
int lwstat(const wchar_t *file_name, struct stat *buf)
|
||||
int lwstat(const wcstring &file_name, struct stat *buf)
|
||||
{
|
||||
// fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
|
||||
cstring tmp = wcs2string(file_name);
|
||||
|
@ -180,31 +180,31 @@ int lwstat(const wchar_t *file_name, struct stat *buf)
|
|||
}
|
||||
|
||||
|
||||
int waccess(const wchar_t *file_name, int mode)
|
||||
int waccess(const wcstring &file_name, int mode)
|
||||
{
|
||||
cstring tmp = wcs2string(file_name);
|
||||
return access(tmp.c_str(), mode);
|
||||
}
|
||||
|
||||
int wunlink(const wchar_t *file_name)
|
||||
int wunlink(const wcstring &file_name)
|
||||
{
|
||||
cstring tmp = wcs2string(file_name);
|
||||
return unlink(tmp.c_str());
|
||||
}
|
||||
|
||||
void wperror(const wchar_t *s)
|
||||
void wperror(const wcstring &s)
|
||||
{
|
||||
int e = errno;
|
||||
if( s != 0 )
|
||||
if( !s.empty() )
|
||||
{
|
||||
fwprintf( stderr, L"%ls: ", s );
|
||||
fwprintf( stderr, L"%ls: ", s.c_str() );
|
||||
}
|
||||
fwprintf( stderr, L"%s\n", strerror( e ) );
|
||||
}
|
||||
|
||||
#ifdef HAVE_REALPATH_NULL
|
||||
|
||||
wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
|
||||
wchar_t *wrealpath(const wcstring &pathname, wchar_t *resolved_path)
|
||||
{
|
||||
cstring tmp = wcs2string(pathname);
|
||||
char *narrow_res = realpath( tmp.c_str(), 0 );
|
||||
|
@ -346,7 +346,7 @@ wcstring wgettext2(const wcstring &in) {
|
|||
return result;
|
||||
}
|
||||
|
||||
const wchar_t *wgetenv( const wchar_t *name )
|
||||
const wchar_t *wgetenv( const wcstring &name )
|
||||
{
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
cstring name_narrow = wcs2string(name);
|
||||
|
@ -361,13 +361,13 @@ const wchar_t *wgetenv( const wchar_t *name )
|
|||
|
||||
}
|
||||
|
||||
int wmkdir( const wchar_t *name, int mode )
|
||||
int wmkdir( const wcstring &name, int mode )
|
||||
{
|
||||
cstring name_narrow = wcs2string(name);
|
||||
return mkdir( name_narrow.c_str(), mode );
|
||||
}
|
||||
|
||||
int wrename( const wchar_t *old, const wchar_t *newv )
|
||||
int wrename( const wcstring &old, const wcstring &newv )
|
||||
{
|
||||
cstring old_narrow = wcs2string(old);
|
||||
cstring new_narrow =wcs2string(newv);
|
||||
|
|
30
wutil.h
30
wutil.h
|
@ -44,53 +44,53 @@ void wutil_destroy();
|
|||
/**
|
||||
Wide character version of fopen().
|
||||
*/
|
||||
FILE *wfopen(const wchar_t *path, const char *mode);
|
||||
FILE *wfopen(const wcstring &path, const char *mode);
|
||||
|
||||
/**
|
||||
Wide character version of freopen().
|
||||
*/
|
||||
FILE *wfreopen(const wchar_t *path, const char *mode, FILE *stream);
|
||||
FILE *wfreopen(const wcstring &path, const char *mode, FILE *stream);
|
||||
|
||||
/**
|
||||
Wide character version of open().
|
||||
*/
|
||||
int wopen(const wchar_t *pathname, int flags, ...);
|
||||
int wopen(const wcstring &pathname, int flags, ...);
|
||||
|
||||
/**
|
||||
Wide character version of creat().
|
||||
*/
|
||||
int wcreat(const wchar_t *pathname, mode_t mode);
|
||||
int wcreat(const wcstring &pathname, mode_t mode);
|
||||
|
||||
|
||||
/**
|
||||
Wide character version of opendir().
|
||||
*/
|
||||
DIR *wopendir(const wchar_t *name);
|
||||
DIR *wopendir(const wcstring &name);
|
||||
|
||||
/**
|
||||
Wide character version of stat().
|
||||
*/
|
||||
int wstat(const wchar_t *file_name, struct stat *buf);
|
||||
int wstat(const wcstring &file_name, struct stat *buf);
|
||||
|
||||
/**
|
||||
Wide character version of lstat().
|
||||
*/
|
||||
int lwstat(const wchar_t *file_name, struct stat *buf);
|
||||
int lwstat(const wcstring &file_name, struct stat *buf);
|
||||
|
||||
/**
|
||||
Wide character version of access().
|
||||
*/
|
||||
int waccess(const wchar_t *pathname, int mode);
|
||||
int waccess(const wcstring &pathname, int mode);
|
||||
|
||||
/**
|
||||
Wide character version of unlink().
|
||||
*/
|
||||
int wunlink(const wchar_t *pathname);
|
||||
int wunlink(const wcstring &pathname);
|
||||
|
||||
/**
|
||||
Wide character version of perror().
|
||||
*/
|
||||
void wperror(const wchar_t *s);
|
||||
void wperror(const wcstring &s);
|
||||
|
||||
/**
|
||||
Wide character version of getcwd().
|
||||
|
@ -100,7 +100,7 @@ wchar_t *wgetcwd( wchar_t *buff, size_t sz );
|
|||
/**
|
||||
Wide character version of chdir()
|
||||
*/
|
||||
int wchdir( const wchar_t * dir );
|
||||
int wchdir( const wcstring &dir );
|
||||
|
||||
/**
|
||||
Wide character version of realpath function. Just like the GNU
|
||||
|
@ -108,7 +108,7 @@ int wchdir( const wchar_t * dir );
|
|||
second argument, in which case the result will be allocated using
|
||||
malloc, and must be free'd by the user.
|
||||
*/
|
||||
wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path);
|
||||
wchar_t *wrealpath(const wcstring &pathname, wchar_t *resolved_path);
|
||||
|
||||
/**
|
||||
Wide character version of readdir()
|
||||
|
@ -139,16 +139,16 @@ wcstring wgettext2(const wcstring &in);
|
|||
/**
|
||||
Wide character version of getenv
|
||||
*/
|
||||
const wchar_t *wgetenv( const wchar_t *name );
|
||||
const wchar_t *wgetenv( const wcstring &name );
|
||||
|
||||
/**
|
||||
Wide character version of mkdir
|
||||
*/
|
||||
int wmkdir( const wchar_t *dir, int mode );
|
||||
int wmkdir( const wcstring &dir, int mode );
|
||||
|
||||
/**
|
||||
Wide character version of rename
|
||||
*/
|
||||
int wrename( const wchar_t *oldName, const wchar_t *newName );
|
||||
int wrename( const wcstring &oldName, const wcstring &newName );
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue