libsmack: clean up redundant stuff
authorJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Thu, 5 Dec 2013 18:18:02 +0000 (20:18 +0200)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Mon, 9 Dec 2013 13:10:16 +0000 (15:10 +0200)
Cleaned up redundant constants and code. Grouped related constants
nearby each other.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
(cherry picked from commit d6f8c52011013f536b7171c2d1f3e9c5ecfaf2f9)

libsmack/libsmack.c

index 4dea889..ad65ca4 100644 (file)
 #include <limits.h>
 #include <sys/xattr.h>
 
+#define SELF_LABEL_FILE "/proc/self/attr/current"
+
 #define SHORT_LABEL_LEN 23
 #define ACC_LEN 6
 #define LOAD_LEN (2 * (SMACK_LABEL_LEN + 1) + 2 * ACC_LEN + 1)
+#define KERNEL_LONG_FORMAT "%s %s %s"
+#define KERNEL_SHORT_FORMAT "%-23s %-23s %5.5s"
+#define KERNEL_MODIFY_FORMAT "%s %s %s %s"
 
 #define LEVEL_MAX 255
 #define NUM_LEN 4
 #define CIPSO_MAX_SIZE CIPSO_POS(CAT_MAX_COUNT)
 #define CIPSO_NUM_LEN_STR "%-4d"
 
-#define KERNEL_LONG_FORMAT "%s %s %s"
-#define KERNEL_SHORT_FORMAT "%-23s %-23s %5.5s"
-#define KERNEL_MODIFY_FORMAT "%s %s %s %s"
-#define READ_BUF_SIZE LOAD_LEN + 1
-#define SELF_LABEL_FILE "/proc/self/attr/current"
-#define ACC_CLEAR "-----"
-
 #define ACCESS_TYPE_R 0x01
 #define ACCESS_TYPE_W 0x02
 #define ACCESS_TYPE_X 0x04
@@ -91,7 +89,6 @@ struct smack_cipso {
 };
 
 static int accesses_apply(struct smack_accesses *handle, int clear);
-static ssize_t smack_label_length(const char *label) __attribute__((unused));
 static inline ssize_t get_label(char *dest, const char *src);
 static inline int str_to_access_code(const char *str);
 static inline void access_code_to_str(unsigned code, char *str);
@@ -253,7 +250,7 @@ int smack_accesses_add_modify(struct smack_accesses *handle,
 int smack_accesses_add_from_file(struct smack_accesses *accesses, int fd)
 {
        FILE *file = NULL;
-       char buf[READ_BUF_SIZE];
+       char buf[LOAD_LEN + 1];
        char *ptr;
        const char *subject, *object, *access, *access2;
        int newfd;
@@ -269,7 +266,7 @@ int smack_accesses_add_from_file(struct smack_accesses *accesses, int fd)
                return -1;
        }
 
-       while (fgets(buf, READ_BUF_SIZE, file) != NULL) {
+       while (fgets(buf, LOAD_LEN + 1, file) != NULL) {
                if (strcmp(buf, "\n") == 0)
                        continue;
                subject = strtok_r(buf, " \t\n", &ptr);