补交 244/2
authorpenglei <1624952103@qq.com>
Sat, 8 Jun 2024 04:05:03 +0000 (12:05 +0800)
committerpenglei <1624952103@qq.com>
Sat, 8 Jun 2024 04:05:03 +0000 (12:05 +0800)
code/sdk/drivers/peripheral/utils/custom_utils.c

index a3a32f7..9a683ea 100644 (file)
@@ -1577,7 +1577,7 @@ void uapi_delete_files(void)
 
 int uapi_save_exc(void)
 {
-    const char *folderPath =  "/user/exc";
+    const char *folderPath = "/user/exc";
     const char *tarPath = "/user/tar/exc_%d.tar";
 
     DIR *dir;
@@ -1589,6 +1589,7 @@ int uapi_save_exc(void)
 
     size_t bytesRead = 0;
     FILE *fp;
+    struct stat file_inf;
     int ret = 0;
 
     uint32_t timestamp = get_local_timestamp();
@@ -1599,14 +1600,14 @@ int uapi_save_exc(void)
     ret = mtar_open(&tar, str, "w");
     if (ret != MTAR_ESUCCESS) 
     {
-        PRINT("Unable to open/create %s\r\n",str);
+        PRINT("unable to open/create %s\r\n",str);
         return -1;
     }
 
     dir = opendir(folderPath);
     if (dir == NULL) 
     {
-        PRINT("Unable to open %s\r\n",folderPath);
+        PRINT("unable to open %s\r\n",folderPath);
         return -1;
     }
 
@@ -1615,18 +1616,22 @@ int uapi_save_exc(void)
         if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) 
         {
             char filePath[64];
-            snprintf(filePath, sizeof(filePath), "%s/%s", filePath, entry->d_name);
+            snprintf(filePath, sizeof(filePath), "%s/%s", folderPath, entry->d_name);
 
             fp = fopen(filePath, "r");
             if(fp == NULL) 
             {
-                PRINT("Unable to open %s\n", filePath);
+                PRINT("uable to open %s\r\n", filePath);
                 return -1;
             }
 
-            while ((bytesRead = fread(buffer, 1, sizeof(buffer), fp) > 0) )
+            memset(&file_inf, 0, sizeof(file_inf));
+            stat(filePath, &file_inf);
+            
+            mtar_write_file_header(&tar, entry->d_name, file_inf.st_size);
+
+            while((bytesRead = fread(buffer, 1, sizeof(buffer), fp)) > 0)
             {
-                mtar_write_file_header(&tar, entry->d_name, bytesRead);
                 mtar_write_data(&tar, buffer, bytesRead);
                 
                 memset(buffer, 0, sizeof(buffer));