diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-15 14:13:09 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-15 14:13:09 +0000 |
commit | 94c3331d47ae08167e5122a3023ffc3340274698 (patch) | |
tree | 56125536e0c17df62ce4e8b50449d89b1a424103 | |
parent | b4b6d262872c1e3887efc2836e8dd2f64e8651eb (diff) | |
download | busybox-w32-94c3331d47ae08167e5122a3023ffc3340274698.tar.gz busybox-w32-94c3331d47ae08167e5122a3023ffc3340274698.tar.bz2 busybox-w32-94c3331d47ae08167e5122a3023ffc3340274698.zip |
- an empty middle term in ?: violates ISO C
- use shorter boilerplate and use C89 style comments
-rw-r--r-- | libbb/loop.c | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/libbb/loop.c b/libbb/loop.c index f7029d591..06b5185b6 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
@@ -2,21 +2,9 @@ | |||
2 | /* | 2 | /* |
3 | * Utility routines. | 3 | * Utility routines. |
4 | * | 4 | * |
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 8 | */ |
21 | 9 | ||
22 | 10 | ||
@@ -75,11 +63,12 @@ extern int del_loop(const char *device) | |||
75 | return rc; | 63 | return rc; |
76 | } | 64 | } |
77 | 65 | ||
78 | // Returns 0 if mounted RW, 1 if mounted read-only, <0 for error. | 66 | /* Returns 0 if mounted RW, 1 if mounted read-only, <0 for error. |
79 | // *device is loop device to use, or if *device==NULL finds a loop device to | 67 | *device is loop device to use, or if *device==NULL finds a loop device to |
80 | // mount it on and sets *device to a strdup of that loop device name. This | 68 | mount it on and sets *device to a strdup of that loop device name. This |
81 | // search will re-use an existing loop device already bound to that | 69 | search will re-use an existing loop device already bound to that |
82 | // file/offset if it finds one. | 70 | file/offset if it finds one. |
71 | */ | ||
83 | extern int set_loop(char **device, const char *file, int offset) | 72 | extern int set_loop(char **device, const char *file, int offset) |
84 | { | 73 | { |
85 | char dev[20]; | 74 | char dev[20]; |
@@ -87,37 +76,39 @@ extern int set_loop(char **device, const char *file, int offset) | |||
87 | struct stat statbuf; | 76 | struct stat statbuf; |
88 | int i, dfd, ffd, mode, rc=1; | 77 | int i, dfd, ffd, mode, rc=1; |
89 | 78 | ||
90 | // Open the file. Barf if this doesn't work. | 79 | /* Open the file. Barf if this doesn't work. */ |
91 | if((ffd = open(file, mode=O_RDWR))<0 && (ffd = open(file,mode=O_RDONLY))<0) | 80 | if((ffd = open(file, mode=O_RDWR))<0 && (ffd = open(file,mode=O_RDONLY))<0) |
92 | return errno; | 81 | return errno; |
93 | 82 | ||
94 | // Find a loop device | 83 | /* Find a loop device. */ |
95 | for(i=0;rc;i++) { | 84 | for(i=0;rc;i++) { |
96 | sprintf(dev, LOOP_FORMAT, i++); | 85 | sprintf(dev, LOOP_FORMAT, i++); |
97 | // Ran out of block devices, return failure. | 86 | /* Ran out of block devices, return failure. */ |
98 | if(stat(*device ? : dev, &statbuf) || !S_ISBLK(statbuf.st_mode)) { | 87 | if(stat(*device ? *device : dev, &statbuf) || |
88 | !S_ISBLK(statbuf.st_mode)) { | ||
99 | rc=ENOENT; | 89 | rc=ENOENT; |
100 | break; | 90 | break; |
101 | } | 91 | } |
102 | // Open the sucker and check its loopiness. | 92 | /* Open the sucker and check its loopiness. */ |
103 | if((dfd=open(dev, mode))<0 && errno==EROFS) | 93 | if((dfd=open(dev, mode))<0 && errno==EROFS) |
104 | dfd=open(dev,mode=O_RDONLY); | 94 | dfd=open(dev,mode=O_RDONLY); |
105 | if(dfd<0) continue; | 95 | if(dfd<0) continue; |
106 | 96 | ||
107 | rc=ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); | 97 | rc=ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); |
108 | // If device free, claim it. | 98 | /* If device free, claim it. */ |
109 | if(rc && errno==ENXIO) { | 99 | if(rc && errno==ENXIO) { |
110 | memset(&loopinfo, 0, sizeof(loopinfo)); | 100 | memset(&loopinfo, 0, sizeof(loopinfo)); |
111 | safe_strncpy(loopinfo.lo_file_name, file, LO_NAME_SIZE); | 101 | safe_strncpy(loopinfo.lo_file_name, file, LO_NAME_SIZE); |
112 | loopinfo.lo_offset = offset; | 102 | loopinfo.lo_offset = offset; |
113 | // Associate free loop device with file | 103 | /* Associate free loop device with file. */ |
114 | if(!ioctl(dfd, LOOP_SET_FD, ffd) && | 104 | if(!ioctl(dfd, LOOP_SET_FD, ffd) && |
115 | !ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0; | 105 | !ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0; |
116 | else ioctl(dfd, LOOP_CLR_FD, 0); | 106 | else ioctl(dfd, LOOP_CLR_FD, 0); |
117 | // If this block device already set up right, re-use it. | 107 | /* If this block device already set up right, re-use it. |
118 | // (Yes this is racy, but associating two loop devices with the same | 108 | (Yes this is racy, but associating two loop devices with the same |
119 | // file isn't pretty either. In general, mounting the same file twice | 109 | file isn't pretty either. In general, mounting the same file twice |
120 | // without using losetup manually is problematic.) | 110 | without using losetup manually is problematic.) |
111 | */ | ||
121 | } else if(strcmp(file,loopinfo.lo_file_name) | 112 | } else if(strcmp(file,loopinfo.lo_file_name) |
122 | || offset!=loopinfo.lo_offset) rc=1; | 113 | || offset!=loopinfo.lo_offset) rc=1; |
123 | close(dfd); | 114 | close(dfd); |