enhanced error handling of sio,pio,tio

This commit is contained in:
2012-02-12 13:20:39 +00:00
parent 3df521f7a9
commit a2346f6e4b
21 changed files with 1104 additions and 525 deletions

View File

@ -22,7 +22,7 @@ static int test1 (void)
fio = qse_fio_open (
QSE_MMGR_GETDFL(),
0,
QSE_T("fio1.txt"),
QSE_T("fio01-1.txt"),
QSE_FIO_READ|QSE_FIO_WRITE|QSE_FIO_CREATE|QSE_FIO_TRUNCATE,
QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH
);
@ -107,7 +107,7 @@ static int test2 (void)
fio = qse_fio_open (
QSE_MMGR_GETDFL(),
0,
QSE_T("fio2.txt"),
QSE_T("fio01-2.txt"),
QSE_FIO_CREATE | QSE_FIO_TRUNCATE | QSE_FIO_APPEND,
QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH
);
@ -216,16 +216,16 @@ static int test3 (void)
{
qse_fio_t* fio;
qse_ssize_t n;
const qse_char_t* x = QSE_T("\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?");
const qse_mchar_t* x = QSE_MT("this is a test string");
qse_fio_off_t off;
qse_char_t buf[1000];
qse_mchar_t buf[1000];
fio = qse_fio_open (
QSE_MMGR_GETDFL(),
0,
QSE_T("fio3.txt"),
QSE_T("fio01-3.txt"),
QSE_FIO_TEXT | QSE_FIO_READ | QSE_FIO_WRITE |
QSE_FIO_READ | QSE_FIO_WRITE |
QSE_FIO_CREATE | QSE_FIO_TRUNCATE,
QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH
@ -236,29 +236,24 @@ static int test3 (void)
return -1;
}
n = qse_fio_write (fio, x, qse_strlen(x));
n = qse_fio_write (fio, x, qse_mbslen(x));
qse_printf (QSE_T("written %d chars\n"), (int)n);
n = qse_fio_flush (fio);
qse_printf (QSE_T("flushed %d chars\n"), (int)n);
off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN);
if (off == (qse_fio_off_t)-1)
{
qse_printf (QSE_T("failed to get file offset\n"));
}
n = qse_fio_read (fio, buf, QSE_COUNTOF(buf));
qse_printf (QSE_T("read %d chars\n"), (int)n);
if (n > 0)
{
qse_printf (QSE_T("[%.*s]\n"), (int)n, buf);
qse_printf (QSE_T("[%.*hs]\n"), (int)n, buf);
}
qse_fio_close (fio);
return 0;
}
@ -275,7 +270,7 @@ int main ()
R (test3);
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
qse_printf (QSE_T("Run \"rm -f fio?.txt\" to delete garbages\n"));
qse_printf (QSE_T("Run \"rm -f fio01-?.txt\" to delete garbages\n"));
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
return 0;

View File

@ -52,8 +52,8 @@ static int pio1 (const qse_char_t* cmd, qse_env_t* env, int oflags, qse_pio_hid_
if (n <= -1)
{
qse_printf (
QSE_T("qse_pio_read() returned error - %s\n"),
qse_pio_geterrmsg(pio)
QSE_T("qse_pio_read() returned error - %d\n"),
(int)qse_pio_geterrnum(pio)
);
break;
}
@ -74,8 +74,7 @@ static int pio1 (const qse_char_t* cmd, qse_env_t* env, int oflags, qse_pio_hid_
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
if (x <= -1)
{
qse_printf (QSE_T("error code : %d, error string: %s\n"),
(int)qse_pio_geterrnum(pio), qse_pio_geterrmsg(pio));
qse_printf (QSE_T("error code : %d\n"), (int)qse_pio_geterrnum(pio));
}
qse_pio_close (pio);
@ -111,8 +110,8 @@ static int pio2 (const qse_char_t* cmd, qse_env_t* env, int oflags, qse_pio_hid_
if (n < 0)
{
qse_printf (
QSE_T("qse_pio_read() returned error - %s\n"),
qse_pio_geterrmsg(pio)
QSE_T("qse_pio_read() returned error - %d\n"),
(int)qse_pio_geterrnum(pio)
);
break;
}
@ -129,8 +128,7 @@ static int pio2 (const qse_char_t* cmd, qse_env_t* env, int oflags, qse_pio_hid_
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
if (x <= -1)
{
qse_printf (QSE_T("error code : %d, error string: %s\n"),
(int)qse_pio_geterrnum(pio), qse_pio_geterrmsg(pio));
qse_printf (QSE_T("error code : %d\n"), (int)qse_pio_geterrnum(pio));
}
qse_pio_close (pio);
@ -394,7 +392,7 @@ static int test13 (void)
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
if (x == -1)
{
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)QSE_PIO_ERRNUM(pio), qse_pio_geterrmsg(pio));
qse_printf (QSE_T("error code : %d\n"), (int)QSE_PIO_ERRNUM(pio));
}
qse_pio_close (pio);

View File

@ -30,6 +30,7 @@
# include <sys/sendfile.h>
#endif
/* TODO: WIN32 TransmitFile */
#if defined(HAVE_SENDFILE) && defined(HAVE_SENDFILE64)
# if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_SENDFILE64)
# define xsendfile sendfile64
@ -270,6 +271,7 @@ qse_printf (QSE_T("opening file [%hs] for reading\n"), path);
return -1;
}
/* check if it is a link. symbolic link??? */
if (!S_ISREG(st.st_mode))
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_EACCES);