comparison input/input.c @ 36152:c3b4a1b48c7d

Make 0 termination code more robust against future changes.
author reimar
date Tue, 07 May 2013 20:39:17 +0000
parents 5302a565ada7
children affa86541a51
comparison
equal deleted inserted replaced
36151:63bc09af21f4 36152:c3b4a1b48c7d
1606 buffer[0] = 0; 1606 buffer[0] = 0;
1607 while(1) { 1607 while(1) {
1608 int bs = strlen(buffer); 1608 int bs = strlen(buffer);
1609 if(! eof && bs < BS_MAX-1) { 1609 if(! eof && bs < BS_MAX-1) {
1610 int r = read(fd,buffer+bs,BS_MAX-1-bs); 1610 int r = read(fd,buffer+bs,BS_MAX-1-bs);
1611 if (r > 0) bs += r;
1612 buffer[bs] = 0;
1611 if(r < 0) { 1613 if(r < 0) {
1612 if(errno == EINTR) 1614 if(errno == EINTR)
1613 continue; 1615 continue;
1614 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrReadingInputConfig,file,strerror(errno)); 1616 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrReadingInputConfig,file,strerror(errno));
1615 close(fd); 1617 close(fd);
1616 return 0; 1618 return 0;
1617 } 1619 }
1618 eof = r == 0; 1620 eof = r == 0;
1619 bs += r;
1620 buffer[bs] = 0;
1621 } 1621 }
1622 // Empty buffer : return 1622 // Empty buffer : return
1623 if(!buffer[0]) { 1623 if(!buffer[0]) {
1624 mp_msg(MSGT_INPUT,MSGL_V,"Input config file %s parsed: %d binds\n",file,n_binds); 1624 mp_msg(MSGT_INPUT,MSGL_V,"Input config file %s parsed: %d binds\n",file,n_binds);
1625 close(fd); 1625 close(fd);