Fix a bug where wfopen would always fail

Removed some buffer_t
This commit is contained in:
ridiculousfish 2012-03-03 22:48:21 -08:00
parent 8a46931e34
commit 087940ec9e
5 changed files with 27 additions and 36 deletions

View file

@ -173,11 +173,6 @@ static bool is_electric(const wcstring &key)
*/
static null_terminated_array_t<char> export_array;
/**
Buffer used for storing string contents for export_arr
*/
static buffer_t export_buffer;
/**
Flag for checking if we need to regenerate the exported variable
@ -507,8 +502,6 @@ void env_init()
wchar_t *uname;
wchar_t *version;
b_init( &export_buffer );
/*
env_read_only variables can not be altered directly by the user
*/
@ -671,8 +664,6 @@ void env_destroy()
{
env_universal_destroy();
b_destroy( &export_buffer );
while( &top->env != global )
{
env_pop();

View file

@ -49,6 +49,7 @@
#endif
#include <errno.h>
#include <vector>
#include "fallback.h"
#include "util.h"
@ -136,11 +137,11 @@ static struct termios saved_modes;
static int is_ca_mode = 0;
/**
This buffer_t is used to buffer the output of the pager to improve
This buffer is used to buffer the output of the pager to improve
screen redraw performance bu cutting down the number of write()
calls to only one.
*/
static buffer_t pager_buffer;
static std::vector<char> pager_buffer;
/**
The environment variables used to specify the color of different
@ -340,7 +341,7 @@ static wint_t readch()
*/
static int pager_buffered_writer( char c)
{
b_append( &pager_buffer, &c, 1 );
pager_buffer.push_back(c);
return 0;
}
@ -349,8 +350,10 @@ static int pager_buffered_writer( char c)
*/
static void pager_flush()
{
write_loop( 1, pager_buffer.buff, pager_buffer.used );
pager_buffer.used = 0;
if (! pager_buffer.empty()) {
write_loop( 1, & pager_buffer.at(0), pager_buffer.size() * sizeof(char) );
pager_buffer.clear();
}
}
/**

View file

@ -228,30 +228,28 @@ static void test_convert()
int i;
buffer_t sb;
std::vector<char> sb;
say( L"Testing wide/narrow string conversion" );
b_init( &sb );
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
{
wchar_t *w;
char *o, *n;
const char *o, *n;
char c;
sb.used=0;
sb.clear();
while( rand() % ESCAPE_TEST_LENGTH )
{
c = rand ();
b_append( &sb, &c, 1 );
sb.push_back(c);
}
c = 0;
b_append( &sb, &c, 1 );
sb.push_back(c);
o = (char *)sb.buff;
o = &sb.at(0);
w = str2wcs(o);
n = wcs2str(w);
@ -265,7 +263,7 @@ static void test_convert()
err( L"Line %d - %d: Conversion cycle of string %s produced different string %s", __LINE__, i, o, n );
}
free( w );
free( n );
free( (void *)n );
}

View file

@ -3360,7 +3360,7 @@ static int read_ni( int fd, io_data_t *io )
parser_t &parser = parser_t::principal_parser();
FILE *in_stream;
wchar_t *buff=0;
buffer_t acc;
std::vector<char> acc;
int des = fd == 0 ? dup(0) : fd;
int res=0;
@ -3371,8 +3371,6 @@ static int read_ni( int fd, io_data_t *io )
return 1;
}
b_init( &acc );
in_stream = fdopen( des, "r" );
if( in_stream != 0 )
{
@ -3394,17 +3392,17 @@ static int read_ni( int fd, io_data_t *io )
/*
Reset buffer on error. We won't evaluate incomplete files.
*/
acc.used=0;
acc.clear();
break;
}
b_append( &acc, buff, c );
acc.insert(acc.end(), buff, buff + c);
}
b_append( &acc, "\0", 1 );
acc_used = acc.used;
str = str2wcs( acc.buff );
b_destroy( &acc );
acc.push_back(0);
acc_used = acc.size();
str = str2wcs(&acc.at(0));
acc.clear();
if( fclose( in_stream ))
{

View file

@ -142,7 +142,8 @@ int wchdir( const wcstring &dir )
FILE *wfopen(const wcstring &path, const char *mode)
{
int permissions = 0, options = 0;
switch (*mode++) {
size_t idx = 0;
switch (mode[idx++]) {
case 'r':
permissions = O_RDONLY;
break;
@ -160,11 +161,11 @@ FILE *wfopen(const wcstring &path, const char *mode)
break;
}
/* Skip binary */
if (*mode == 'b')
mode++;
if (mode[idx] == 'b')
idx++;
/* Consider append option */
if (*mode == '+')
if (mode[idx] == '+')
permissions = O_RDWR;
int fd = wopen_cloexec(path, permissions | options, 0666);