mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-25 06:35:57 -05:00
Implement ascii line-ending conversion for windows
This commit is contained in:
parent
b108edbc52
commit
a806dde1da
@ -614,7 +614,7 @@ int conf_read(char *file) {
|
||||
DPRINTF(E_FATAL,L_CONF,"Malloc eror in io_new()\n");
|
||||
|
||||
DPRINTF(E_DBG,L_CONF,"Loading config file %s\n",conf_file);
|
||||
if(!io_open(hconfig,"file://%U",conf_file)) {
|
||||
if(!io_open(hconfig,"file://%U?ascii=1",conf_file)) {
|
||||
DPRINTF(E_LOG,L_MISC,"Error opening config file: %s\n",io_errstr(hconfig));
|
||||
io_dispose(hconfig);
|
||||
return CONF_E_FOPEN;
|
||||
@ -1255,7 +1255,7 @@ int conf_write(void) {
|
||||
if(!outfile)
|
||||
DPRINTF(E_FATAL,L_CONF,"io_new failed in conf_write\n");
|
||||
|
||||
if(io_open(outfile,"file://%U?mode=w",conf_main_file)) {
|
||||
if(io_open(outfile,"file://%U?mode=w&ascii=1",conf_main_file)) {
|
||||
retval = _conf_write(outfile,conf_main,0,NULL);
|
||||
io_close(outfile);
|
||||
io_dispose(outfile);
|
||||
|
@ -111,7 +111,7 @@ void err_reopen(void) {
|
||||
return;
|
||||
|
||||
io_close(err_file);
|
||||
if(!io_open("file://%U?mode=a",err_filename)) {
|
||||
if(!io_open("file://%U?mode=a&ascii=1",err_filename)) {
|
||||
/* what to do when you lose your logging mechanism? Keep
|
||||
* going?
|
||||
*/
|
||||
|
56
src/io.c
56
src/io.c
@ -898,12 +898,17 @@ int io_readline_timed(IO_PRIVHANDLE *phandle, unsigned char *buf,
|
||||
uint32_t *len, uint32_t *ms) {
|
||||
uint32_t numread = 0;
|
||||
uint32_t to_read;
|
||||
int ascii = 0;
|
||||
|
||||
if(io_option_get(phandle,"ascii",NULL))
|
||||
ascii = 1;
|
||||
|
||||
io_err_printf(IO_LOG_SPAM,"entering readline_timed\n");
|
||||
|
||||
while(numread < (*len - 1)) {
|
||||
to_read = 1;
|
||||
if(io_read_timeout(phandle, buf + numread, &to_read, ms)) {
|
||||
if((!ascii) || (to_read != '\r')) {
|
||||
numread += to_read;
|
||||
if(buf[numread-1] == '\n') {
|
||||
buf[numread-1] = '\0';
|
||||
@ -917,6 +922,7 @@ int io_readline_timed(IO_PRIVHANDLE *phandle, unsigned char *buf,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@ -955,6 +961,14 @@ int io_readline(IO_PRIVHANDLE *phandle, unsigned char *buf,
|
||||
*/
|
||||
int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) {
|
||||
int result;
|
||||
int ascii=0;
|
||||
int must_free=FALSE;
|
||||
unsigned char *real_buffer;
|
||||
unsigned char *dst;
|
||||
|
||||
uint32_t ascii_len;
|
||||
uint32_t index;
|
||||
uint32_t real_len;
|
||||
|
||||
ASSERT(io_initialized); /* call io_init first */
|
||||
ASSERT(phandle);
|
||||
@ -974,10 +988,50 @@ int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
result = phandle->fnptr->fn_write(phandle,buf,len);
|
||||
|
||||
#ifdef WIN32
|
||||
// We won't do ascii mode on non-windows platforms
|
||||
if(io_option_get(phandle,"ascii",NULL))
|
||||
ascii = 1;
|
||||
#endif
|
||||
|
||||
if(ascii) {
|
||||
ascii_len = *len;
|
||||
for(index = 0; index < *len; index++) {
|
||||
if(buf[index] == '\n')
|
||||
ascii_len++;
|
||||
}
|
||||
real_buffer = (unsigned char *)malloc(ascii_len);
|
||||
if(!real_buffer) {
|
||||
io_err_printf(IO_LOG_FATAL,"Could not alloc buffer in io_printf\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
must_free = TRUE;
|
||||
dst = real_buffer;
|
||||
for(index = 0; index < *len; index++) {
|
||||
*dst++ = buf[index];
|
||||
if(buf[index] == '\n')
|
||||
*dst++ = '\r';
|
||||
}
|
||||
real_len = ascii_len;
|
||||
} else {
|
||||
real_buffer = buf; /* just write what was passed */
|
||||
real_len = *len;
|
||||
}
|
||||
|
||||
result = phandle->fnptr->fn_write(phandle,real_buffer,&real_len);
|
||||
|
||||
if(!result)
|
||||
io_err(phandle,IO_E_OTHER);
|
||||
|
||||
if(must_free) {
|
||||
if(real_len == ascii_len) /* lie about how much we wrote */
|
||||
real_len = *len;
|
||||
free(real_buffer);
|
||||
}
|
||||
|
||||
*len = real_len;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ int rxml_open(RXMLHANDLE *vp, char *file,
|
||||
if(!pnew->hfile)
|
||||
RXML_ERROR(pnew,E_RXML_MALLOC);
|
||||
|
||||
if(!io_open(pnew->hfile, "file://%U", file)) {
|
||||
if(!io_open(pnew->hfile, "file://%U?ascii=1", file)) {
|
||||
io_dispose(pnew->hfile);
|
||||
pnew->hfile = NULL;
|
||||
RXML_ERROR(pnew,E_RXML_OPEN);
|
||||
|
@ -56,7 +56,7 @@ int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!io_open(hfile,"file://%U",filename)) {
|
||||
if(!io_open(hfile,"file://%U?ascii=1",filename)) {
|
||||
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading: %s\n",filename,
|
||||
io_errstr(hfile));
|
||||
io_dispose(hfile);
|
||||
|
Loading…
Reference in New Issue
Block a user