mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-12 15:33:23 -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_FATAL,L_CONF,"Malloc eror in io_new()\n");
|
||||||
|
|
||||||
DPRINTF(E_DBG,L_CONF,"Loading config file %s\n",conf_file);
|
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));
|
DPRINTF(E_LOG,L_MISC,"Error opening config file: %s\n",io_errstr(hconfig));
|
||||||
io_dispose(hconfig);
|
io_dispose(hconfig);
|
||||||
return CONF_E_FOPEN;
|
return CONF_E_FOPEN;
|
||||||
@ -1255,7 +1255,7 @@ int conf_write(void) {
|
|||||||
if(!outfile)
|
if(!outfile)
|
||||||
DPRINTF(E_FATAL,L_CONF,"io_new failed in conf_write\n");
|
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);
|
retval = _conf_write(outfile,conf_main,0,NULL);
|
||||||
io_close(outfile);
|
io_close(outfile);
|
||||||
io_dispose(outfile);
|
io_dispose(outfile);
|
||||||
|
@ -111,7 +111,7 @@ void err_reopen(void) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
io_close(err_file);
|
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
|
/* what to do when you lose your logging mechanism? Keep
|
||||||
* going?
|
* going?
|
||||||
*/
|
*/
|
||||||
|
80
src/io.c
80
src/io.c
@ -898,22 +898,28 @@ int io_readline_timed(IO_PRIVHANDLE *phandle, unsigned char *buf,
|
|||||||
uint32_t *len, uint32_t *ms) {
|
uint32_t *len, uint32_t *ms) {
|
||||||
uint32_t numread = 0;
|
uint32_t numread = 0;
|
||||||
uint32_t to_read;
|
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");
|
io_err_printf(IO_LOG_SPAM,"entering readline_timed\n");
|
||||||
|
|
||||||
while(numread < (*len - 1)) {
|
while(numread < (*len - 1)) {
|
||||||
to_read = 1;
|
to_read = 1;
|
||||||
if(io_read_timeout(phandle, buf + numread, &to_read, ms)) {
|
if(io_read_timeout(phandle, buf + numread, &to_read, ms)) {
|
||||||
numread += to_read;
|
if((!ascii) || (to_read != '\r')) {
|
||||||
if(buf[numread-1] == '\n') {
|
numread += to_read;
|
||||||
buf[numread-1] = '\0';
|
if(buf[numread-1] == '\n') {
|
||||||
*len = numread;
|
buf[numread-1] = '\0';
|
||||||
return TRUE;
|
*len = numread;
|
||||||
}
|
return TRUE;
|
||||||
if(!to_read) { /* EOF */
|
}
|
||||||
*len = numread;
|
if(!to_read) { /* EOF */
|
||||||
buf[numread] = '\0';
|
*len = numread;
|
||||||
return TRUE;
|
buf[numread] = '\0';
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -955,13 +961,21 @@ int io_readline(IO_PRIVHANDLE *phandle, unsigned char *buf,
|
|||||||
*/
|
*/
|
||||||
int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) {
|
int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) {
|
||||||
int result;
|
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(io_initialized); /* call io_init first */
|
||||||
ASSERT(phandle);
|
ASSERT(phandle);
|
||||||
ASSERT(phandle->open);
|
ASSERT(phandle->open);
|
||||||
ASSERT(phandle->fnptr);
|
ASSERT(phandle->fnptr);
|
||||||
ASSERT(phandle->fnptr->fn_write);
|
ASSERT(phandle->fnptr->fn_write);
|
||||||
|
|
||||||
if((!phandle) || (!phandle->open) || (!phandle->fnptr)) {
|
if((!phandle) || (!phandle->open) || (!phandle->fnptr)) {
|
||||||
io_err(phandle,IO_E_NOTINIT);
|
io_err(phandle,IO_E_NOTINIT);
|
||||||
*len = 0;
|
*len = 0;
|
||||||
@ -974,10 +988,50 @@ int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) {
|
|||||||
return FALSE;
|
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)
|
if(!result)
|
||||||
io_err(phandle,IO_E_OTHER);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ int rxml_open(RXMLHANDLE *vp, char *file,
|
|||||||
if(!pnew->hfile)
|
if(!pnew->hfile)
|
||||||
RXML_ERROR(pnew,E_RXML_MALLOC);
|
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);
|
io_dispose(pnew->hfile);
|
||||||
pnew->hfile = NULL;
|
pnew->hfile = NULL;
|
||||||
RXML_ERROR(pnew,E_RXML_OPEN);
|
RXML_ERROR(pnew,E_RXML_OPEN);
|
||||||
|
@ -56,7 +56,7 @@ int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
|
|||||||
return FALSE;
|
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,
|
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading: %s\n",filename,
|
||||||
io_errstr(hfile));
|
io_errstr(hfile));
|
||||||
io_dispose(hfile);
|
io_dispose(hfile);
|
||||||
|
Loading…
Reference in New Issue
Block a user