summaryrefslogtreecommitdiff
path: root/ext4_utils
diff options
context:
space:
mode:
authorDavid Anderson <dvander@google.com>2020-07-08 13:39:01 -0700
committerDavid Anderson <dvander@google.com>2020-07-08 15:52:25 -0700
commit166d867c752968c576af537dc09e4150f9889c40 (patch)
tree3a89db3960a92b9266a155317f5a4811a476fa8f /ext4_utils
parent5e625ed81e831ede444da7c9a2cf0efc3977c192 (diff)
downloadextras-166d867c752968c576af537dc09e4150f9889c40.tar.gz
ext4_utils: Don't #define error in a major include.
Including ext4_utils.h breaks in some files because it defines common identifiers (like "error"). Move these into the only .cpp files that use them. Bug: N/A Test: manual test Change-Id: I4605b560d09ec46c24a2c42a463f563cfe438356
Diffstat (limited to 'ext4_utils')
-rw-r--r--ext4_utils/ext4_utils.cpp2
-rw-r--r--ext4_utils/helpers.h25
-rw-r--r--ext4_utils/include/ext4_utils/ext4_utils.h6
-rw-r--r--ext4_utils/wipe.cpp2
4 files changed, 29 insertions, 6 deletions
diff --git a/ext4_utils/ext4_utils.cpp b/ext4_utils/ext4_utils.cpp
index 7c411c89..5175efc0 100644
--- a/ext4_utils/ext4_utils.cpp
+++ b/ext4_utils/ext4_utils.cpp
@@ -36,6 +36,8 @@
#include <sys/disk.h>
#endif
+#include "helpers.h"
+
int force = 0;
struct fs_info info;
struct fs_aux_info aux_info;
diff --git a/ext4_utils/helpers.h b/ext4_utils/helpers.h
new file mode 100644
index 00000000..09b7b457
--- /dev/null
+++ b/ext4_utils/helpers.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <stdio.h>
+#include <string.h>
+
+#define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0)
+#define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); if (!force) longjmp(setjmp_env, EXIT_FAILURE); } while (0)
+#define error_errno(s, args...) error(s ": %s", ##args, strerror(errno))
+#define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); longjmp(setjmp_env, EXIT_FAILURE); } while (0)
+#define critical_error_errno(s, args...) critical_error(s ": %s", ##args, strerror(errno))
diff --git a/ext4_utils/include/ext4_utils/ext4_utils.h b/ext4_utils/include/ext4_utils/ext4_utils.h
index 27156145..b8ddfe13 100644
--- a/ext4_utils/include/ext4_utils/ext4_utils.h
+++ b/ext4_utils/include/ext4_utils/ext4_utils.h
@@ -49,12 +49,6 @@ extern "C" {
extern int force;
-#define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0)
-#define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); if (!force) longjmp(setjmp_env, EXIT_FAILURE); } while (0)
-#define error_errno(s, args...) error(s ": %s", ##args, strerror(errno))
-#define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); longjmp(setjmp_env, EXIT_FAILURE); } while (0)
-#define critical_error_errno(s, args...) critical_error(s ": %s", ##args, strerror(errno))
-
#define EXT4_JNL_BACKUP_BLOCKS 1
#ifndef __cplusplus
diff --git a/ext4_utils/wipe.cpp b/ext4_utils/wipe.cpp
index c2db3353..8b7a66bd 100644
--- a/ext4_utils/wipe.cpp
+++ b/ext4_utils/wipe.cpp
@@ -27,6 +27,8 @@
#include <linux/fs.h>
#include <sys/ioctl.h>
+#include "helpers.h"
+
#ifndef BLKDISCARD
#define BLKDISCARD _IO(0x12,119)
#endif