Skip to content

Commit 4d8a848

Browse files
Merge pull request #22 from tbaederr/master
Rename dprintf() debugging macro to dbg_printf()
2 parents 4d072f6 + dbb7bc4 commit 4d8a848

8 files changed

Lines changed: 93 additions & 93 deletions

File tree

lib/sysfs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ extern struct dlist *get_attributes_list(struct dlist *alist, const char *path);
5454

5555
/* Debugging */
5656
#ifdef DEBUG
57-
#define dprintf(format, arg...) fprintf(stderr, format, ## arg)
57+
#define dbg_printf(format, arg...) fprintf(stderr, format, ## arg)
5858
#else
59-
#define dprintf(format, arg...) do { } while (0)
59+
#define dbg_printf(format, arg...) do { } while (0)
6060
#endif
6161

6262
#endif /* _SYSFS_H_ */

lib/sysfs_attr.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ struct sysfs_attribute *sysfs_open_attribute(const char *path)
105105
}
106106
sysattr = alloc_attribute();
107107
if (!sysattr) {
108-
dprintf("Error allocating attribute at %s\n", path);
108+
dbg_printf("Error allocating attribute at %s\n", path);
109109
return NULL;
110110
}
111111
if (sysfs_get_name_from_path(path, sysattr->name,
112112
SYSFS_NAME_LEN) != 0) {
113-
dprintf("Error retrieving attrib name from path: %s\n", path);
113+
dbg_printf("Error retrieving attrib name from path: %s\n", path);
114114
sysfs_close_attribute(sysattr);
115115
return NULL;
116116
}
117117
safestrcpy(sysattr->path, path);
118118
if ((stat(sysattr->path, &fileinfo)) != 0) {
119-
dprintf("Stat failed: No such attribute?\n");
119+
dbg_printf("Stat failed: No such attribute?\n");
120120
sysattr->method = 0;
121121
free(sysattr);
122122
sysattr = NULL;
@@ -148,25 +148,25 @@ int sysfs_read_attribute(struct sysfs_attribute *sysattr)
148148
return -1;
149149
}
150150
if (!(sysattr->method & SYSFS_METHOD_SHOW)) {
151-
dprintf("Show method not supported for attribute %s\n",
151+
dbg_printf("Show method not supported for attribute %s\n",
152152
sysattr->path);
153153
errno = EACCES;
154154
return -1;
155155
}
156156
pgsize = getpagesize();
157157
fbuf = (char *)calloc(1, pgsize+1);
158158
if (!fbuf) {
159-
dprintf("calloc failed\n");
159+
dbg_printf("calloc failed\n");
160160
return -1;
161161
}
162162
if ((fd = open(sysattr->path, O_RDONLY)) < 0) {
163-
dprintf("Error reading attribute %s\n", sysattr->path);
163+
dbg_printf("Error reading attribute %s\n", sysattr->path);
164164
free(fbuf);
165165
return -1;
166166
}
167167
length = read(fd, fbuf, pgsize);
168168
if (length < 0) {
169-
dprintf("Error reading from attribute %s\n", sysattr->path);
169+
dbg_printf("Error reading from attribute %s\n", sysattr->path);
170170
close(fd);
171171
free(fbuf);
172172
return -1;
@@ -184,7 +184,7 @@ int sysfs_read_attribute(struct sysfs_attribute *sysattr)
184184
close(fd);
185185
vbuf = (char *)realloc(fbuf, length+1);
186186
if (!vbuf) {
187-
dprintf("realloc failed\n");
187+
dbg_printf("realloc failed\n");
188188
free(fbuf);
189189
return -1;
190190
}
@@ -212,7 +212,7 @@ int sysfs_write_attribute(struct sysfs_attribute *sysattr,
212212
}
213213

214214
if (!(sysattr->method & SYSFS_METHOD_STORE)) {
215-
dprintf ("Store method not supported for attribute %s\n",
215+
dbg_printf ("Store method not supported for attribute %s\n",
216216
sysattr->path);
217217
errno = EACCES;
218218
return -1;
@@ -222,12 +222,12 @@ int sysfs_write_attribute(struct sysfs_attribute *sysattr,
222222
* read attribute again to see if we can get an updated value
223223
*/
224224
if ((sysfs_read_attribute(sysattr))) {
225-
dprintf("Error reading attribute\n");
225+
dbg_printf("Error reading attribute\n");
226226
return -1;
227227
}
228228
if ((strncmp(sysattr->value, new_value, sysattr->len)) == 0 &&
229229
(len == sysattr->len)) {
230-
dprintf("Attr %s already has the requested value %s\n",
230+
dbg_printf("Attr %s already has the requested value %s\n",
231231
sysattr->name, new_value);
232232
return 0;
233233
}
@@ -237,18 +237,18 @@ int sysfs_write_attribute(struct sysfs_attribute *sysattr,
237237
* "write" permission
238238
*/
239239
if ((fd = open(sysattr->path, O_WRONLY)) < 0) {
240-
dprintf("Error reading attribute %s\n", sysattr->path);
240+
dbg_printf("Error reading attribute %s\n", sysattr->path);
241241
return -1;
242242
}
243243

244244
length = write(fd, new_value, len);
245245
if (length < 0) {
246-
dprintf("Error writing to the attribute %s - invalid value?\n",
246+
dbg_printf("Error writing to the attribute %s - invalid value?\n",
247247
sysattr->name);
248248
close(fd);
249249
return -1;
250250
} else if ((unsigned int)length != len) {
251-
dprintf("Could not write %zd bytes to attribute %s\n",
251+
dbg_printf("Could not write %zd bytes to attribute %s\n",
252252
len, sysattr->name);
253253
/*
254254
* since we could not write user supplied number of bytes,
@@ -295,12 +295,12 @@ static struct sysfs_attribute *add_attribute_to_list(struct dlist *alist,
295295

296296
attr = sysfs_open_attribute(path);
297297
if (!attr) {
298-
dprintf("Error opening attribute %s\n", path);
298+
dbg_printf("Error opening attribute %s\n", path);
299299
return NULL;
300300
}
301301
if (attr->method & SYSFS_METHOD_SHOW) {
302302
if (sysfs_read_attribute(attr)) {
303-
dprintf("Error reading attribute %s\n", path);
303+
dbg_printf("Error reading attribute %s\n", path);
304304
sysfs_close_attribute(attr);
305305
return NULL;
306306
}
@@ -326,12 +326,12 @@ static struct sysfs_attribute *add_attribute(void *dev, const char *path)
326326

327327
attr = sysfs_open_attribute(path);
328328
if (!attr) {
329-
dprintf("Error opening attribute %s\n", path);
329+
dbg_printf("Error opening attribute %s\n", path);
330330
return NULL;
331331
}
332332
if (attr->method & SYSFS_METHOD_SHOW) {
333333
if (sysfs_read_attribute(attr)) {
334-
dprintf("Error reading attribute %s\n", path);
334+
dbg_printf("Error reading attribute %s\n", path);
335335
sysfs_close_attribute(attr);
336336
return NULL;
337337
}
@@ -397,7 +397,7 @@ struct dlist *read_dir_links(const char *path)
397397
}
398398
dir = opendir(path);
399399
if (!dir) {
400-
dprintf("Error opening directory %s\n", path);
400+
dbg_printf("Error opening directory %s\n", path);
401401
return NULL;
402402
}
403403
while ((dirent = readdir(dir)) != NULL) {
@@ -414,7 +414,7 @@ struct dlist *read_dir_links(const char *path)
414414
linklist = dlist_new_with_delete
415415
(SYSFS_NAME_LEN, sysfs_del_name);
416416
if (!linklist) {
417-
dprintf("Error creating list\n");
417+
dbg_printf("Error creating list\n");
418418
return NULL;
419419
}
420420
}
@@ -469,7 +469,7 @@ struct sysfs_device *sysfs_read_dir_subdirs(const char *path)
469469

470470
dir = opendir(path);
471471
if (!dir) {
472-
dprintf("Error opening directory %s\n", path);
472+
dbg_printf("Error opening directory %s\n", path);
473473
return NULL;
474474
}
475475
while ((dirent = readdir(dir)) != NULL) {
@@ -506,7 +506,7 @@ struct dlist *read_dir_subdirs(const char *path)
506506
}
507507
dir = opendir(path);
508508
if (!dir) {
509-
dprintf("Error opening directory %s\n", path);
509+
dbg_printf("Error opening directory %s\n", path);
510510
return NULL;
511511
}
512512
while ((dirent = readdir(dir)) != NULL) {
@@ -523,7 +523,7 @@ struct dlist *read_dir_subdirs(const char *path)
523523
dirlist = dlist_new_with_delete
524524
(SYSFS_NAME_LEN, sysfs_del_name);
525525
if (!dirlist) {
526-
dprintf("Error creating list\n");
526+
dbg_printf("Error creating list\n");
527527
return NULL;
528528
}
529529
}
@@ -554,7 +554,7 @@ struct dlist *get_attributes_list(struct dlist *alist, const char *path)
554554

555555
dir = opendir(path);
556556
if (!dir) {
557-
dprintf("Error opening directory %s\n", path);
557+
dbg_printf("Error opening directory %s\n", path);
558558
return NULL;
559559
}
560560
while ((dirent = readdir(dir)) != NULL) {
@@ -572,7 +572,7 @@ struct dlist *get_attributes_list(struct dlist *alist, const char *path)
572572
(sizeof(struct sysfs_attribute),
573573
sysfs_del_attribute);
574574
if (!alist) {
575-
dprintf("Error creating list\n");
575+
dbg_printf("Error creating list\n");
576576
return NULL;
577577
}
578578
}
@@ -603,7 +603,7 @@ struct dlist *get_dev_attributes_list(void *dev)
603603
safestrcpy(path, ((struct sysfs_device *)dev)->path);
604604
dir = opendir(path);
605605
if (!dir) {
606-
dprintf("Error opening directory %s\n", path);
606+
dbg_printf("Error opening directory %s\n", path);
607607
return NULL;
608608
}
609609
while ((dirent = readdir(dir)) != NULL) {

lib/sysfs_bus.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus)
115115
safestrcat(devpath, "/");
116116
safestrcat(devpath, curlink);
117117
if (sysfs_get_link(devpath, target, SYSFS_PATH_MAX)) {
118-
dprintf("Error getting link - %s\n", devpath);
118+
dbg_printf("Error getting link - %s\n", devpath);
119119
continue;
120120
}
121121
dev = sysfs_open_device_path(target);
122122
if (!dev) {
123-
dprintf("Error opening device at %s\n",
123+
dbg_printf("Error opening device at %s\n",
124124
target);
125125
continue;
126126
}
@@ -171,7 +171,7 @@ struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus)
171171
safestrcat(drvpath, curdir);
172172
drv = sysfs_open_driver_path(drvpath);
173173
if (!drv) {
174-
dprintf("Error opening driver at %s\n",
174+
dbg_printf("Error opening driver at %s\n",
175175
drvpath);
176176
continue;
177177
}
@@ -202,7 +202,7 @@ struct sysfs_bus *sysfs_open_bus(const char *name)
202202

203203
memset(buspath, 0, SYSFS_PATH_MAX);
204204
if (sysfs_get_mnt_path(buspath, SYSFS_PATH_MAX)) {
205-
dprintf("Sysfs not supported on this system\n");
205+
dbg_printf("Sysfs not supported on this system\n");
206206
return NULL;
207207
}
208208

@@ -211,18 +211,18 @@ struct sysfs_bus *sysfs_open_bus(const char *name)
211211
safestrcat(buspath, "/");
212212
safestrcat(buspath, name);
213213
if (sysfs_path_is_dir(buspath)) {
214-
dprintf("Invalid path to bus: %s\n", buspath);
214+
dbg_printf("Invalid path to bus: %s\n", buspath);
215215
return NULL;
216216
}
217217
bus = alloc_bus();
218218
if (!bus) {
219-
dprintf("calloc failed\n");
219+
dbg_printf("calloc failed\n");
220220
return NULL;
221221
}
222222
safestrcpy(bus->name, name);
223223
safestrcpy(bus->path, buspath);
224224
if (sysfs_remove_trailing_slash(bus->path)) {
225-
dprintf("Incorrect path to bus %s\n", bus->path);
225+
dbg_printf("Incorrect path to bus %s\n", bus->path);
226226
sysfs_close_bus(bus);
227227
return NULL;
228228
}
@@ -259,13 +259,13 @@ struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus,
259259
safestrcat(devpath, "/");
260260
safestrcat(devpath, id);
261261
if (sysfs_path_is_link(devpath)) {
262-
dprintf("No such device %s on bus %s?\n", id, bus->name);
262+
dbg_printf("No such device %s on bus %s?\n", id, bus->name);
263263
return NULL;
264264
}
265265
if (!sysfs_get_link(devpath, target, SYSFS_PATH_MAX)) {
266266
dev = sysfs_open_device_path(target);
267267
if (!dev) {
268-
dprintf("Error opening device at %s\n", target);
268+
dbg_printf("Error opening device at %s\n", target);
269269
return NULL;
270270
}
271271
if (!bus->devices)
@@ -307,7 +307,7 @@ struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
307307
safestrcat(drvpath, drvname);
308308
drv = sysfs_open_driver_path(drvpath);
309309
if (!drv) {
310-
dprintf("Error opening driver at %s\n", drvpath);
310+
dbg_printf("Error opening driver at %s\n", drvpath);
311311
return NULL;
312312
}
313313
if (!bus->drivers)

0 commit comments

Comments
 (0)