~ubuntu-branches/ubuntu/quantal/ezstream/quantal

« back to all changes in this revision

Viewing changes to src/playlist.c

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-09-27 16:50:53 UTC
  • mfrom: (1.1.3 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090927165053-jkfio6ahwa723q0q
Tags: 0.5.6~dfsg-1
* New upstream release 
* Bumped standards version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $Id: playlist.c 15794 2009-03-18 09:10:28Z moritz $     */
 
1
/*      $Id: playlist.c 16536 2009-08-30 21:46:15Z moritz $     */
2
2
/*
3
3
 * Copyright (c) 2007, 2009 Moritz Grimm <mdgrimm@gmx.net>
4
4
 *
131
131
        FILE            *filep;
132
132
        char             buf[PATH_MAX];
133
133
 
134
 
        pl = playlist_create(filename);
135
 
 
136
 
        if ((filep = fopen(filename, "r")) == NULL) {
137
 
                printf("%s: %s: %s\n", __progname, filename, strerror(errno));
138
 
                playlist_free(&pl);
139
 
                return (NULL);
 
134
        if (filename != NULL) {
 
135
                pl = playlist_create(filename);
 
136
 
 
137
                if ((filep = fopen(filename, "r")) == NULL) {
 
138
                        printf("%s: %s: %s\n", __progname, filename, strerror(errno));
 
139
                        playlist_free(&pl);
 
140
                        return (NULL);
 
141
                }
 
142
        } else {
 
143
                pl = playlist_create("stdin");
 
144
 
 
145
                if ((filep = fdopen(STDIN_FILENO, "r")) == NULL) {
 
146
                        printf("%s: stdin: %s\n", __progname, strerror(errno));
 
147
                        playlist_free(&pl);
 
148
                        return (NULL);
 
149
                }
140
150
        }
141
151
 
142
152
        line = 0;
147
157
                        char skip_buf[2];
148
158
 
149
159
                        printf("%s[%lu]: File or path name too long\n",
150
 
                               filename, line);
 
160
                               pl->filename, line);
151
161
                        /* Discard any excess chars in that line. */
152
162
                        while (fgets(skip_buf, (int)sizeof(skip_buf), filep) != NULL) {
153
163
                                if (skip_buf[0] == '\n')
181
191
        }
182
192
        if (ferror(filep)) {
183
193
                printf("%s: playlist_read(): Error while reading %s: %s\n",
184
 
                       __progname, filename, strerror(errno));
 
194
                       __progname, pl->filename, strerror(errno));
185
195
                fclose(filep);
186
196
                playlist_free(&pl);
187
197
                return (NULL);
499
509
        }
500
510
 
501
511
        if (fgets(buf, (int)sizeof(buf), filep) == NULL) {
502
 
                if (ferror(filep))
 
512
                int     errnum = errno;
 
513
 
 
514
                pclose(filep);
 
515
 
 
516
                if (ferror(filep)) {
503
517
                        printf("%s: Error while reading output from program '%s': %s\n",
504
 
                               __progname, pl->filename, strerror(errno));
505
 
                pclose(filep);
506
 
                printf("%s: FATAL: External program '%s' not (or no longer) usable.\n",
507
 
                       __progname, pl->filename);
508
 
                exit(1);
 
518
                               __progname, pl->filename, strerror(errnum));
 
519
                        exit(1);
 
520
                }
 
521
 
 
522
                /* No output (end of playlist.) */
 
523
                return (NULL);
509
524
        }
510
525
 
511
526
        pclose(filep);
518
533
 
519
534
        buf[strcspn(buf, "\n")] = '\0';
520
535
        buf[strcspn(buf, "\r")] = '\0';
521
 
        if (buf[0] == '\0') {
522
 
                printf("%s: Empty line received from program '%s'\n",
523
 
                       __progname, pl->filename);
 
536
        if (buf[0] == '\0')
 
537
                /* Empty line (end of playlist.) */
524
538
                return (NULL);
525
 
        }
526
539
 
527
540
        if (pl->prog_track != NULL)
528
541
                xfree(pl->prog_track);