diff --git a/bin/lint-fix.sh b/bin/lint-fix.sh index 525d831..b3394d5 100755 --- a/bin/lint-fix.sh +++ b/bin/lint-fix.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh if [ ! -f ".clang-format" ]; then echo ".clang-format file not found!" @@ -8,9 +8,12 @@ fi changed=0 for file in $(find . -name '*.c' -o -name '*.h'); do - formatted="$(clang-format -style=file "${file}")" - if ! echo "${formatted}" | cmp - "${file}" >/dev/null; then - echo "${formatted}" > "${file}" + tmp="$(mktemp)" + clang-format -style=file "${file}" > "${tmp}" + if cmp "${tmp}" "${file}" >/dev/null; then + rm "${tmp}" + else + mv "${tmp}" "${file}" echo "Formatted ${file}" changed=1 fi diff --git a/bin/lint.sh b/bin/lint.sh index 71a3fb6..ab97dbf 100755 --- a/bin/lint.sh +++ b/bin/lint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh if [ ! -f ".clang-format" ]; then echo ".clang-format file not found!" @@ -8,10 +8,13 @@ fi failures=0 for file in $(find . -name '*.c' -o -name '*.h'); do echo "Checking ${file}" - diff -u <(clang-format -style=file "${file}") "${file}" + tmp="$(mktemp)" + clang-format -style=file "${file}" > "${tmp}" + diff -u "${tmp}" "${file}" if [[ $? -gt 0 ]]; then failures=$((failures + 1)) fi + rm "${tmp}" done [[ "${failures}" -eq 0 ]] || exit 1