* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / sound / sound_firmware.c
blobc446e98e01c4fe4a64b0eb107e74fa0ac4be1adb
1 #include "os.h"
2 #define __KERNEL_SYSCALLS__
3 #include <linux/module.h>
4 #include <linux/fs.h>
5 #include <linux/mm.h>
6 #include <linux/malloc.h>
7 #include <linux/unistd.h>
8 #include <asm/uaccess.h>
10 static int errno;
11 static int do_mod_firmware_load(const char *fn, char **fp)
13 int fd;
14 long l;
15 char *dp;
17 fd = open(fn, 0, 0);
18 if (fd == -1)
20 printk(KERN_INFO "Unable to load '%s'.\n", fn);
21 return 0;
23 l = lseek(fd, 0L, 2);
24 if (l <= 0 || l > 131072)
26 printk(KERN_INFO "Invalid firmware '%s'\n", fn);
27 sys_close(fd);
28 return 0;
30 lseek(fd, 0L, 0);
31 dp = vmalloc(l);
32 if (dp == NULL)
34 printk(KERN_INFO "Out of memory loading '%s'.\n", fn);
35 sys_close(fd);
36 return 0;
38 if (read(fd, dp, l) != l)
40 printk(KERN_INFO "Failed to read '%s'.\n", fn);
41 vfree(dp);
42 sys_close(fd);
43 return 0;
45 close(fd);
46 *fp = dp;
47 return (int) l;
50 int mod_firmware_load(const char *fn, char **fp)
52 int r;
53 mm_segment_t fs = get_fs();
55 set_fs(get_ds());
56 r = do_mod_firmware_load(fn, fp);
57 set_fs(fs);
58 return r;