aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-06-15 18:06:21 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-06-15 18:06:21 +0000
commit80dd76db7f927be1b6a967f43f36d705b701f153 (patch)
tree8d95e5e8eaaa92c3e581b1c991c0f82cdb33d435
parent28d6bb796a0cf53c8d53e0de78e00e1fedcbf02d (diff)
downloadmpd-80dd76db7f927be1b6a967f43f36d705b701f153.tar.gz
mpd-80dd76db7f927be1b6a967f43f36d705b701f153.tar.xz
mpd-80dd76db7f927be1b6a967f43f36d705b701f153.zip
fix C99 stuff for commandError
also some slight optimizations to interfacePrintWithFD() and myfprintf() git-svn-id: https://svn.musicpd.org/mpd/trunk@1503 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/command.c25
-rw-r--r--src/command.h4
-rw-r--r--src/directory.c14
-rw-r--r--src/interface.c17
-rw-r--r--src/interface.h2
-rw-r--r--src/myfprintf.c19
-rw-r--r--src/player.c2
-rw-r--r--src/playlist.c7
-rw-r--r--src/volume.c11
9 files changed, 53 insertions, 48 deletions
diff --git a/src/command.c b/src/command.c
index 81398ebaf..03899cb17 100644
--- a/src/command.c
+++ b/src/command.c
@@ -164,7 +164,7 @@ int handlePlay(FILE * fp, unsigned int * permission, int argArrayLength,
song = strtol(argArray[1],&test,10);
if(*test!='\0') {
commandError(fp, ACK_ERROR_ARG,
- "need a positive integer");
+ "need a positive integer", NULL);
return -1;
}
}
@@ -181,7 +181,7 @@ int handlePlayId(FILE * fp, unsigned int * permission, int argArrayLength,
id = strtol(argArray[1],&test,10);
if(*test!='\0') {
commandError(fp, ACK_ERROR_ARG,
- "need a positive integer");
+ "need a positive integer", NULL);
return -1;
}
}
@@ -309,7 +309,7 @@ int handleDelete(FILE * fp, unsigned int * permission, int argArrayLength,
song = strtol(argArray[1],&test,10);
if(*test!='\0') {
commandError(fp, ACK_ERROR_ARG,
- "need a positive integer");
+ "need a positive integer", NULL);
return -1;
}
return deleteFromPlaylist(fp,song);
@@ -324,7 +324,7 @@ int handleDeleteId(FILE * fp, unsigned int * permission, int argArrayLength,
id = strtol(argArray[1],&test,10);
if(*test!='\0') {
commandError(fp, ACK_ERROR_ARG,
- "need a positive integer");
+ "need a positive integer", NULL);
return -1;
}
return deleteFromPlaylistById(fp, id);
@@ -387,7 +387,8 @@ int handlePlaylistChanges(FILE * fp, unsigned int * permission,
version = strtoul(argArray[1], &test, 10);
if(*test!='\0') {
- commandError(fp, ACK_ERROR_ARG, "need a positive integer");
+ commandError(fp, ACK_ERROR_ARG, "need a positive integer",
+ NULL);
return -1;
}
return playlistChanges(fp, version);
@@ -403,7 +404,7 @@ int handlePlaylistInfo(FILE * fp, unsigned int * permission,
song = strtol(argArray[1],&test,10);
if(*test!='\0') {
commandError(fp, ACK_ERROR_ARG,
- "%s need a positive integer");
+ "need a positive integer", NULL);
return -1;
}
}
@@ -420,7 +421,7 @@ int handlePlaylistId(FILE * fp, unsigned int * permission,
id = strtol(argArray[1],&test,10);
if(*test!='\0') {
commandError(fp, ACK_ERROR_ARG,
- "%s need a positive integer");
+ "need a positive integer", NULL);
return -1;
}
}
@@ -509,7 +510,7 @@ int handleVolume(FILE * fp, unsigned int * permission, int argArrayLength,
change = strtol(argArray[1],&test,10);
if(*test!='\0') {
- commandError(fp, ACK_ERROR_ARG, "need an integer");
+ commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1;
}
return changeVolumeLevel(fp,change,1);
@@ -523,7 +524,7 @@ int handleSetVol(FILE * fp, unsigned int * permission, int argArrayLength,
level = strtol(argArray[1],&test,10);
if(*test!='\0') {
- commandError(fp, ACK_ERROR_ARG, "need an integer");
+ commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1;
}
return changeVolumeLevel(fp,level,0);
@@ -537,7 +538,7 @@ int handleRepeat(FILE * fp, unsigned int * permission, int argArrayLength,
status = strtol(argArray[1],&test,10);
if(*test!='\0') {
- commandError(fp, ACK_ERROR_ARG, "need an integer");
+ commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1;
}
return setPlaylistRepeatStatus(fp,status);
@@ -551,7 +552,7 @@ int handleRandom(FILE * fp, unsigned int * permission, int argArrayLength,
status = strtol(argArray[1],&test,10);
if(*test!='\0') {
- commandError(fp, ACK_ERROR_ARG, "need an integer");
+ commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1;
}
return setPlaylistRandomStatus(fp,status);
@@ -730,7 +731,7 @@ int handlePassword(FILE * fp, unsigned int * permission, int argArrayLength,
char ** argArray)
{
if(getPermissionFromPassword(argArray[1],permission)<0) {
- commandError(fp, ACK_ERROR_PASSWORD, "incorrect password");
+ commandError(fp, ACK_ERROR_PASSWORD, "incorrect password", NULL);
return -1;
}
diff --git a/src/command.h b/src/command.h
index f08ebb16a..cf8874a17 100644
--- a/src/command.h
+++ b/src/command.h
@@ -50,13 +50,13 @@ void finishCommands();
if(current_command) { \
myfprintf(fp, "ACK [%i@%i] {%s} " format "\n", \
(int)error, command_listNum, \
- current_command, ##__VA_ARGS__); \
+ current_command, __VA_ARGS__); \
current_command = NULL; \
} \
else { \
myfprintf(stderr, "ACK [%i@%i] " format "\n", \
(int)error, command_listNum, \
- ##__VA_ARGS__); \
+ __VA_ARGS__); \
} \
}
diff --git a/src/directory.c b/src/directory.c
index 0d1b0ee2b..a05553dd6 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -166,7 +166,8 @@ void readDirectoryDBIfUpdateIsFinished() {
int updateInit(FILE * fp, List * pathList) {
if(directory_updatePid > 0) {
- commandError(fp, ACK_ERROR_UPDATE_ALREADY, "already updating");
+ commandError(fp, ACK_ERROR_UPDATE_ALREADY, "already updating",
+ NULL);
return -1;
}
@@ -224,7 +225,7 @@ int updateInit(FILE * fp, List * pathList) {
unblockSignals();
ERROR("updateInit: Problems forking()'ing\n");
commandError(fp, ACK_ERROR_SYSTEM,
- "problems trying to update");
+ "problems trying to update", NULL);
directory_updatePid = 0;
return -1;
}
@@ -745,7 +746,8 @@ int printDirectoryInfo(FILE * fp, char * name) {
Directory * directory;
if((directory = getDirectory(name))==NULL) {
- commandError(fp, ACK_ERROR_NO_EXIST, "directory not found");
+ commandError(fp, ACK_ERROR_NO_EXIST, "directory not found",
+ NULL);
return -1;
}
@@ -1047,7 +1049,7 @@ int traverseAllIn(FILE * fp, char * name,
return forEachSong(fp, song, data);
}
commandError(fp, ACK_ERROR_NO_EXIST,
- "directory or file not found");
+ "directory or file not found", NULL);
return -1;
}
@@ -1129,7 +1131,7 @@ int searchForSongsIn(FILE * fp, char * name, char * item, char * string) {
ret = traverseAllIn(fp,name,searchForFilenameInDirectory,NULL,
(void *)dup);
}
- else commandError(fp, ACK_ERROR_ARG, "unknown table");
+ else commandError(fp, ACK_ERROR_ARG, "unknown table", NULL);
free(dup);
@@ -1166,7 +1168,7 @@ int findSongsIn(FILE * fp, char * name, char * item, char * string) {
(void *)string);
}
- commandError(fp, ACK_ERROR_ARG, "unknown table");
+ commandError(fp, ACK_ERROR_ARG, "unknown table", NULL);
return -1;
}
diff --git a/src/interface.c b/src/interface.c
index 89229050d..29e372a5e 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -542,20 +542,21 @@ void flushAllInterfaceBuffers() {
}
}
-int interfacePrintWithFD(int fd,char * buffer) {
- int i;
- int buflen;
+int interfacePrintWithFD(int fd, char * buffer, int buflen) {
+ static int i = 0;
int copylen;
Interface * interface;
- if(!(buflen = strlen(buffer))) return -1;
-
- for(i=0;i<interface_max_connections;i++) {
- if(interfaces[i].open && interfaces[i].fd==fd) break;
+ if(i>=interface_max_connections ||
+ !interfaces[i].open || interfaces[i].fd!=fd)
+ {
+ for(i=0;i<interface_max_connections;i++) {
+ if(interfaces[i].open && interfaces[i].fd==fd) break;
+ }
+ if(i==interface_max_connections) return -1;
}
/* if fd isn't found or interfaces is going to be closed, do nothing */
- if(i==interface_max_connections) return -1;
if(interfaces[i].expired) return 0;
interface = interfaces+i;
diff --git a/src/interface.h b/src/interface.h
index ccd94b23a..1f87ba7fe 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -33,7 +33,7 @@ void freeAllInterfaces();
void closeOldInterfaces();
void closeInterfaceWithFD(int fd);
void flushAllInterfaceBuffers();
-int interfacePrintWithFD(int fd, char * buffer);
+int interfacePrintWithFD(int fd, char * buffer, int len);
int doIOForInterfaces();
diff --git a/src/myfprintf.c b/src/myfprintf.c
index 42bc0049a..e2c366a1d 100644
--- a/src/myfprintf.c
+++ b/src/myfprintf.c
@@ -37,8 +37,7 @@ FILE * myfprintf_err;
char * myfprintf_outFilename;
char * myfprintf_errFilename;
-void blockingWrite(int fd, char * string) {
- int len = strlen(string);
+void blockingWrite(int fd, char * string, int len) {
int ret;
while(len) {
@@ -71,28 +70,26 @@ void myfprintf(FILE * fp, char * format, ... ) {
char buffer[BUFFER_LENGTH+1];
va_list arglist;
int fd = fileno(fp);
- int fcntlret;
memset(buffer,0,BUFFER_LENGTH+1);
va_start(arglist,format);
- while((fcntlret=fcntl(fd,F_GETFL))==-1 && errno==EINTR);
if(myfprintf_stdLogMode && (fd==1 || fd==2)) {
time_t t = time(NULL);
if(fd==1) fp = myfprintf_out;
else fp = myfprintf_err;
strftime(buffer,14,"%b %e %R",localtime(&t));
- blockingWrite(fd,buffer);
- blockingWrite(fd," : ");
+ blockingWrite(fd,buffer,strlen(buffer));
+ blockingWrite(fd," : ",3);
vsnprintf(buffer,BUFFER_LENGTH,format,arglist);
- blockingWrite(fd,buffer);
+ blockingWrite(fd,buffer,strlen(buffer));
}
else {
+ int len;
vsnprintf(buffer,BUFFER_LENGTH,format,arglist);
- if(!(fcntlret & O_NONBLOCK) ||
- interfacePrintWithFD(fd,buffer)<0)
- {
- blockingWrite(fd,buffer);
+ len = strlen(buffer);
+ if(interfacePrintWithFD(fd,buffer,len)<0) {
+ blockingWrite(fd,buffer,len);
}
}
diff --git a/src/player.c b/src/player.c
index 4188243e6..0ca57bbb4 100644
--- a/src/player.c
+++ b/src/player.c
@@ -382,7 +382,7 @@ int playerSeek(FILE * fp, Song * song, float time) {
if(pc->state==PLAYER_STATE_STOP) {
commandError(fp, ACK_ERROR_PLAYER_SYNC,
- "player not currently playing");
+ "player not currently playing", NULL);
return -1;
}
diff --git a/src/playlist.c b/src/playlist.c
index 3da74754a..7c5410c66 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -609,7 +609,7 @@ int addToPlaylist(FILE * fp, char * url) {
int addSongToPlaylist(FILE * fp, Song * song) {
if(playlist.length==playlist_max_length) {
commandError(fp, ACK_ERROR_PLAYLIST_MAX,
- "playlist is at the max size");
+ "playlist is at the max size", NULL);
return -1;
}
@@ -1248,7 +1248,7 @@ int deletePlaylist(FILE * fp, char * utf8file) {
if(unlink(actualFile)<0) {
commandError(fp, ACK_ERROR_SYSTEM,
- "problems deleting file");
+ "problems deleting file", NULL);
return -1;
}
@@ -1293,7 +1293,8 @@ int savePlaylist(FILE * fp, char * utf8file) {
while(!(fileP = fopen(actualFile,"w")) && errno==EINTR);
if(fileP==NULL) {
- commandError(fp, ACK_ERROR_SYSTEM, "problems opening file");
+ commandError(fp, ACK_ERROR_SYSTEM, "problems opening file",
+ NULL);
return -1;
}
diff --git a/src/volume.c b/src/volume.c
index 4a1370b2f..fa2f8aaa9 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -145,7 +145,7 @@ int changeOssVolumeLevel(FILE * fp, int change, int rel) {
if (rel) {
if((current = getOssVolumeLevel()) < 0) {
commandError(fp, ACK_ERROR_SYSTEM,
- "problem getting current volume");
+ "problem getting current volume", NULL);
return -1;
}
@@ -159,7 +159,8 @@ int changeOssVolumeLevel(FILE * fp, int change, int rel) {
level = (new << 8) + new;
if(ioctl(volume_ossFd,MIXER_WRITE(volume_ossControl),&level) < 0) {
- commandError(fp, ACK_ERROR_SYSTEM, "problems setting volume");
+ commandError(fp, ACK_ERROR_SYSTEM, "problems setting volume",
+ NULL);
return -1;
}
@@ -271,7 +272,8 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) {
if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem,
SND_MIXER_SCHN_FRONT_LEFT,&level))<0) {
- commandError(fp, ACK_ERROR_SYSTEM, "problems getting volume");
+ commandError(fp, ACK_ERROR_SYSTEM, "problems getting volume",
+ NULL);
WARNING("problems getting alsa volume: %s\n",snd_strerror(err));
return -1;
}
@@ -297,7 +299,8 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) {
if((err = snd_mixer_selem_set_playback_volume_all(
volume_alsaElem,level))<0) {
- commandError(fp, ACK_ERROR_SYSTEM, "problems setting volume");
+ commandError(fp, ACK_ERROR_SYSTEM, "problems setting volume",
+ NULL);
WARNING("problems setting alsa volume: %s\n",snd_strerror(err));
return -1;
}