gpllib: Introduce typedefs for callbacks
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Thu, 6 Aug 2009 04:03:04 +0000 (21:03 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Thu, 6 Aug 2009 04:29:35 +0000 (21:29 -0700)
typedefs are evil but useful for function pointers as it makes them more
readable and maintainable.

This fixes a bug by the way: we had

   void *callback(struct driveinfo *, struct part_entry *, int, int)

where we should have had

   void (*callback)(struct driveinfo *, struct part_entry *, int, int)

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/gplinclude/disk/msdos.h
com32/gpllib/disk/msdos.c

index c8dcb1d..405b9b9 100644 (file)
@@ -11,7 +11,9 @@
 #define _MSDOS_H_
 
 #include <disk/geom.h>
+#include <disk/partition.h>
 
-int parse_partition_table(struct driveinfo *, void *);
+typedef void (*p_callback)(struct driveinfo *, struct part_entry *, int, int);
+int parse_partition_table(struct driveinfo *, p_callback);
 
 #endif /* _MSDOS_H_ */
index 249d39c..e69aa71 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <disk/common.h>
 #include <disk/geom.h>
+#include <disk/msdos.h>
 #include <disk/partition.h>
 #include <disk/read.h>
 
@@ -40,7 +41,7 @@ static inline int msdos_magic_present(const char *ptab)
  **/
 static int process_extended_partition(struct driveinfo *drive_info,
                                       int partition_offset,
-                                      void *callback(struct driveinfo *, struct part_entry *, int, int),
+                                      p_callback callback,
                                       int nb_part_seen)
 {
        int status = 0;
@@ -102,7 +103,7 @@ static int process_extended_partition(struct driveinfo *drive_info,
  * @callback:  Callback to execute
  **/
 static int process_mbr(struct driveinfo *drive_info, struct part_entry *ptab,
-                      void *callback(struct driveinfo *, struct part_entry *, int, int))
+                      p_callback callback)
 {
        int status = 0;
 
@@ -132,7 +133,6 @@ static int process_mbr(struct driveinfo *drive_info, struct part_entry *ptab,
  * parse_partition_table - execute a callback for each partition entry
  * @d:         driveinfo struct describing the drive
  * @callback:  Callback to execute
- * @error:     Return the error code (I/O), if needed
  *
  * The signature of the callback should be the following:
  *
@@ -141,7 +141,7 @@ static int process_mbr(struct driveinfo *drive_info, struct part_entry *ptab,
  *              int offset_root,
  *              int nb_part_seen)
  **/
-int parse_partition_table(struct driveinfo *d, void *callback)
+int parse_partition_table(struct driveinfo *d, p_callback callback)
 {
        char *mbr = malloc(SECTOR * sizeof(char));