]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
fade.c: Fix some signed issues
authorAndre Noll <maan@systemlinux.org>
Sat, 26 May 2007 20:39:23 +0000 (22:39 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 26 May 2007 20:39:23 +0000 (22:39 +0200)
Don't sleep at all if the sleep time passed via comamnd line args
are negative.

fade.c

diff --git a/fade.c b/fade.c
index 9ba733b3113ca0273143e95892266c236938631f..8893ca606e0d7e85ddf69513b0790214cb7452c7 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -127,16 +127,17 @@ out:
  * Open mixer, get volume, fade to new_vol in secs seconds and
  * close mixer
  */
  * Open mixer, get volume, fade to new_vol in secs seconds and
  * close mixer
  */
-static int fade(int new_vol, unsigned int secs)
+static void fade(int new_vol, int fade_time)
 {
 {
-       int vol, mixer_fd = -1, diff, incr, ret;
+       int vol, mixer_fd = -1, diff, incr;
+       unsigned secs;
        struct timespec ts;
        unsigned long long tmp, tmp2; /* Careful with that axe, Eugene! */
 
        struct timespec ts;
        unsigned long long tmp, tmp2; /* Careful with that axe, Eugene! */
 
-       PARA_NOTICE_LOG("fading to %d in %d seconds\n", new_vol, secs);
-       ret = 0;
-       if (!secs)
+       if (fade_time <= 0)
                goto out;
                goto out;
+       secs = fade_time;
+       PARA_NOTICE_LOG("fading to %d in %d seconds\n", new_vol, secs);
        mixer_fd = open_mixer();
        if (mixer_fd < 0)
                goto out;
        mixer_fd = open_mixer();
        if (mixer_fd < 0)
                goto out;
@@ -146,7 +147,6 @@ static int fade(int new_vol, unsigned int secs)
        diff = new_vol - vol;
        if (!diff) {
                sleep(secs);
        diff = new_vol - vol;
        if (!diff) {
                sleep(secs);
-               ret = 1;
                goto out;
        }
        incr = diff > 0? 1: -1;
                goto out;
        }
        incr = diff > 0? 1: -1;
@@ -166,7 +166,6 @@ static int fade(int new_vol, unsigned int secs)
 out:
        if (mixer_fd >= 0)
                close(mixer_fd);
 out:
        if (mixer_fd >= 0)
                close(mixer_fd);
-       return 1;
 }
 
 static int client_cmd(const char *cmd,...)
 }
 
 static int client_cmd(const char *cmd,...)
@@ -254,13 +253,18 @@ static void sweet_dreams(void)
 
 static void snooze(void)
 {
 
 static void snooze(void)
 {
+       unsigned sleep_time;
+
+       if (args_info.snooze_time_arg <= 0)
+               return;
+       sleep_time = args_info.snooze_time_arg;
        if (get_vol() < args_info.snooze_out_vol_arg)
                set_vol(args_info.snooze_out_vol_arg);
        else
                fade(args_info.snooze_out_vol_arg, args_info.snooze_out_fade_arg);
        client_cmd("pause");
        PARA_NOTICE_LOG("%d seconds snooze time...\n", args_info.snooze_time_arg);
        if (get_vol() < args_info.snooze_out_vol_arg)
                set_vol(args_info.snooze_out_vol_arg);
        else
                fade(args_info.snooze_out_vol_arg, args_info.snooze_out_fade_arg);
        client_cmd("pause");
        PARA_NOTICE_LOG("%d seconds snooze time...\n", args_info.snooze_time_arg);
-       sleep(args_info.snooze_time_arg);
+       sleep(sleep_time);
        client_cmd("play");
        fade(args_info.snooze_in_vol_arg, args_info.snooze_in_fade_arg);
 }
        client_cmd("play");
        fade(args_info.snooze_in_vol_arg, args_info.snooze_in_fade_arg);
 }