How to get error result of unlink

后端 未结 3 1297
北海茫月
北海茫月 2021-02-07 10:41

If a call to unlink() returns false for the specified path, how do you find out what the reason for the failure was (i.e. EISDIR, ENOENT, ELOOP etc.)? PHP 5.x running on redhat

3条回答
  •  不知归路
    2021-02-07 11:14

    This is not possible, i'm afraid. Here's the C code that handles unlink in php 5.3.

    ret = VCWD_UNLINK(url); <-- calls unlink(2)
    if (ret == -1) {
        if (options & REPORT_ERRORS) {
            php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(errno));
        }
        return 0;
    }
    

    as you can see, errno is not returned and there's no way to access it later.

    There's already a bugreport about this, but it doesn't seem to draw too much attention. ;)

    See also this discussion

提交回复
热议问题