+#ifdef TUNEFS
+/**
+ * Removes all existing instances of the parameter passed in \a param,
+ * which are in the form of "key=<value>", from the buffer at \a buf.
+ *
+ * The parameter can be either in the form of "key" when passed by option
+ * "--erase-param", or in the form of "key=<value>" when passed by option
+ * "--param".
+ *
+ * \param buf the buffer holding on-disk server parameters.
+ * \param param the parameter whose instances are to be removed from \a buf.
+ * \param withval true means the parameter is in the form of "key=<value>"
+ * false means the parameter is in the form of "key"
+ *
+ * \retval 0 success, parameter was erased,
+ * \retval 1 success, parameter was not found, don't need to do erase_ldd,
+ * \retval EINVAL failure, invalid input parameter.
+ */
+static int erase_param(const char *const buf, const char *const param,
+ bool withval)
+{
+ char search[PARAM_MAX + 1] = "";
+ char *buffer = (char *)buf;
+ bool found = false;
+
+ if (strlen(param) > PARAM_MAX) {
+ fprintf(stderr, "%s: param to erase is too long-\n%s\n",
+ progname, param);
+ return EINVAL;
+ }
+
+ /* add_param() writes a space as the first character in ldd_params */
+ search[0] = ' ';
+
+ /* "key" or "key=<value>" */
+ if (withval) {
+ char *keyend;
+
+ keyend = strchr(param, '=');
+ if (!keyend)
+ return EINVAL;
+ strncpy(&search[1], param, keyend - param + 1);
+ } else {
+ strncpy(&search[1], param, strlen(param));
+ strncat(search, "=", 1);
+ }
+
+ while (1) {
+ char *space;
+
+ buffer = strstr(buffer, search);
+ if (!buffer)
+ return found == true ? 0 : 1;
+ found = true;
+ space = strchr(buffer + 1, ' ');
+ if (space) {
+ memmove(buffer, space, strlen(space) + 1);
+ } else {
+ *buffer = '\0';
+ return 0;
+ }
+ }
+}
+#endif
+