Browse Source

[Pal] Allow zero size read/write on PAL streams

Isaku Yamahata 4 years ago
parent
commit
7495dffda7
4 changed files with 10 additions and 13 deletions
  1. 7 11
      Pal/src/db_streams.c
  2. 3 0
      Pal/src/pal.h
  3. 0 1
      Pal/src/pal_error.c
  4. 0 1
      Pal/src/pal_error.h

+ 7 - 11
Pal/src/db_streams.c

@@ -254,9 +254,6 @@ int64_t _DkStreamRead(PAL_HANDLE handle, uint64_t offset, uint64_t count, void*
     if (!ops)
         return -PAL_ERROR_BADHANDLE;
 
-    if (!count)
-        return -PAL_ERROR_ZEROSIZE;
-
     int64_t ret;
 
     if (addr) {
@@ -275,7 +272,8 @@ int64_t _DkStreamRead(PAL_HANDLE handle, uint64_t offset, uint64_t count, void*
 }
 
 /* PAL call DkStreamRead: Read from stream at absolute offset. Return number
-   of bytes if succeeded, or 0 for failure. Error code is notified. */
+   of bytes if succeeded,
+   or PAL_STREAM_ERROR for failure. Error code is notified. */
 PAL_NUM
 DkStreamRead(PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count, PAL_PTR buffer, PAL_PTR source,
              PAL_NUM size) {
@@ -291,7 +289,7 @@ DkStreamRead(PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count, PAL_PTR buffer, P
 
     if (ret < 0) {
         _DkRaiseFailure(-ret);
-        ret = 0;
+        ret = PAL_STREAM_ERROR;
     }
 
     LEAVE_PAL_CALL_RETURN(ret);
@@ -304,10 +302,7 @@ int64_t _DkStreamWrite(PAL_HANDLE handle, uint64_t offset, uint64_t count, const
     const struct handle_ops* ops = HANDLE_OPS(handle);
 
     if (!ops)
-        return -PAL_ERROR_BADHANDLE;;
-
-    if (!count)
-        return -PAL_ERROR_ZEROSIZE;
+        return -PAL_ERROR_BADHANDLE;
 
     int64_t ret;
 
@@ -327,7 +322,8 @@ int64_t _DkStreamWrite(PAL_HANDLE handle, uint64_t offset, uint64_t count, const
 }
 
 /* PAL call DkStreamWrite: Write to stream at absolute offset. Return number
-   of bytes if succeeded, or 0 for failure. Error code is notified. */
+   of bytes if succeeded,
+   or PAL_STREAM_ERROR for failure. Error code is notified. */
 PAL_NUM
 DkStreamWrite(PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count, PAL_PTR buffer, PAL_STR dest) {
     ENTER_PAL_CALL(DkStreamWrite);
@@ -342,7 +338,7 @@ DkStreamWrite(PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count, PAL_PTR buffer,
 
     if (ret < 0) {
         _DkRaiseFailure(-ret);
-        ret = 0;
+        ret = PAL_STREAM_ERROR;
     }
 
     LEAVE_PAL_CALL_RETURN(ret);

+ 3 - 0
Pal/src/pal.h

@@ -333,6 +333,9 @@ DkProcessExit (PAL_NUM exitCode);
 #define PAL_OPTION_CLOEXEC       01000
 #define PAL_OPTION_EFD_SEMAPHORE 02000
 
+/* error value of read/write */
+#define PAL_STREAM_ERROR        ((PAL_NUM)-1L)
+
 #define WITHIN_MASK(val, mask)  (((val)|(mask)) == (mask))
 
 PAL_HANDLE

+ 0 - 1
Pal/src/pal_error.c

@@ -45,7 +45,6 @@ static const struct pal_error_description pal_error_list[] = {
     { PAL_ERROR_ENDOFSTREAM, "End of stream" },
     { PAL_ERROR_NOTSERVER, "Not a server" },
     { PAL_ERROR_NOTCONNECTION, "Not a connection" },
-    { PAL_ERROR_ZEROSIZE, "Zero size" },
     { PAL_ERROR_CONNFAILED, "Connection failed" },
     { PAL_ERROR_ADDRNOTEXIST, "Resource address does not exist" },
     { PAL_ERROR_AFNOSUPPORT, "Address family not supported by protocol" },

+ 0 - 1
Pal/src/pal_error.h

@@ -49,7 +49,6 @@ typedef enum _pal_error_t {
     PAL_ERROR_ENDOFSTREAM,
     PAL_ERROR_NOTSERVER,
     PAL_ERROR_NOTCONNECTION,
-    PAL_ERROR_ZEROSIZE,
     PAL_ERROR_CONNFAILED,
     PAL_ERROR_ADDRNOTEXIST,
     PAL_ERROR_AFNOSUPPORT,