Permalink
Browse files

Use None as the error value instead of -1.

This is a little more conventional, and I'm going to get rid of -1 in
the regex functions as well.
  • Loading branch information...
Andy Chu
Andy Chu committed Jun 15, 2018
1 parent 9b16199 commit f427f914b24b77f990ca71326192343b5a8039e6
Showing with 11 additions and 17 deletions.
  1. +1 −1 native/libc.c
  2. +7 −13 native/libc_test.py
  3. +3 −3 tools/readlink.py
View
@@ -40,7 +40,7 @@ func_realpath(PyObject *self, PyObject *args) {
if (status == NULL) {
debug("error from realpath()");
return PyLong_FromLong(-1);
Py_RETURN_NONE;
}
return PyString_FromString(target);
View
@@ -94,19 +94,13 @@ def testRegexFirstGroupMatch(self):
libc.regex_first_group_match('(X.)', s, 6))
def testRealpathFailOnNonexistentDirectory(self):
# This behaviour is actually inconsistent with GNU readlink,
# but matches behaviour of busybox readlink
# (https://github.com/jgunthorpe/busybox)
self.assertEqual(
-1,
libc.realpath('_tmp/nonexistent')
)
# Consistent with GNU
self.assertEqual(
-1,
libc.realpath('_tmp/nonexistent/supernonexistent')
)
# This behaviour is actually inconsistent with GNU readlink,
# but matches behaviour of busybox readlink
# (https://github.com/jgunthorpe/busybox)
self.assertEqual(None, libc.realpath('_tmp/nonexistent'))
# Consistent with GNU
self.assertEqual(None, libc.realpath('_tmp/nonexistent/supernonexistent'))
if __name__ == '__main__':
View
@@ -16,9 +16,9 @@ def main(argv):
if not arg.f:
util.error("-f must be passed")
return 1
for arg in argv[i:]:
res = libc.realpath(arg)
if res == -1:
for path in argv[i:]:
res = libc.realpath(path)
if res is None:
return 1
print(res)
return 0

0 comments on commit f427f91

Please sign in to comment.