coverity appeasement
[minix.git] / commands / ramdisk / ramdisk.c
blobd46bbca88004bb8e433d18c2a2824808255d677a
2 #include <paths.h>
4 #include <sys/ioc_memory.h>
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <stdlib.h>
9 int
10 main(int argc, char *argv[])
12 int fd;
13 signed long size;
14 char *d;
16 if(argc < 2 || argc > 3) {
17 fprintf(stderr, "usage: %s <size in kB> [device]\n",
18 argv[0]);
19 return 1;
22 d = argc == 2 ? _PATH_RAMDISK : argv[2];
23 if((fd=open(d, O_RDONLY)) < 0) {
24 perror(d);
25 return 1;
28 #define KFACTOR 1024
29 size = atol(argv[1])*KFACTOR;
31 if(size < 0) {
32 fprintf(stderr, "size should be non-negative.\n");
33 return 1;
36 if(ioctl(fd, MIOCRAMSIZE, &size) < 0) {
37 perror("MIOCRAMSIZE");
38 return 1;
41 fprintf(stderr, "size on %s set to %dkB\n", d, size/KFACTOR);
43 return 0;