2 * Advanced Linux Sound Architecture Control Program - Support routines
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <alsa/asoundlib.h>
36 int file_map(const char *filename, char **buf, size_t *bufsize)
41 fd = open(filename, O_RDONLY);
46 if (fstat(fd, &stats) < 0) {
51 *buf = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
52 if (*buf == MAP_FAILED) {
56 *bufsize = stats.st_size;
63 void file_unmap(void *buf, size_t bufsize)
68 size_t line_width(const char *buf, size_t bufsize, size_t pos)
73 for (count = pos; count < bufsize; count++) {
74 if (!esc && buf[count] == '\n')
76 esc = buf[count] == '\\';
82 void initfailed(int cardnumber, const char *reason)
87 if (statefile == NULL)
89 if (snd_card_get_name(cardnumber, &str) < 0)
91 fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644);
92 write(fp, str, strlen(str));
94 write(fp, reason, strlen(reason));