diff options
| author | 2014-03-13 02:01:54 +0100 | |
|---|---|---|
| committer | 2014-03-13 02:42:44 +0100 | |
| commit | 637bd29c70c54bf1d6cf2dfeee0c82da8b604657 (patch) | |
| tree | 8624fd78e25700fddd5ba7684859a08b6e5544ad /src/afc.c | |
| parent | d78d4e1a959e0c21bc9be025dc4fa6a577853ad3 (diff) | |
| download | libimobiledevice-637bd29c70c54bf1d6cf2dfeee0c82da8b604657.tar.gz libimobiledevice-637bd29c70c54bf1d6cf2dfeee0c82da8b604657.tar.bz2 | |
afc: use static buffers where possible
Diffstat (limited to 'src/afc.c')
| -rw-r--r-- | src/afc.c | 59 |
1 files changed, 30 insertions, 29 deletions
| @@ -810,11 +810,13 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, | |||
| 810 | debug_info("current count is %i but length is %i", current_count, length); | 810 | debug_info("current count is %i but length is %i", current_count, length); |
| 811 | 811 | ||
| 812 | /* Send the read command */ | 812 | /* Send the read command */ |
| 813 | AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); | 813 | struct { |
| 814 | packet->filehandle = handle; | 814 | uint64_t handle; |
| 815 | packet->size = htole64(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); | 815 | uint64_t size; |
| 816 | ret = afc_dispatch_packet(client, AFC_OP_READ, (const char*)packet, sizeof(AFCFilePacket), NULL, 0, &bytes_loc); | 816 | } readinfo; |
| 817 | free(packet); | 817 | readinfo.handle = handle; |
| 818 | readinfo.size = htole64(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); | ||
| 819 | ret = afc_dispatch_packet(client, AFC_OP_READ, (const char*)&readinfo, sizeof(readinfo), NULL, 0, &bytes_loc); | ||
| 818 | 820 | ||
| 819 | if (ret != AFC_E_SUCCESS) { | 821 | if (ret != AFC_E_SUCCESS) { |
| 820 | afc_unlock(client); | 822 | afc_unlock(client); |
| @@ -943,9 +945,11 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) | |||
| 943 | */ | 945 | */ |
| 944 | afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation) | 946 | afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation) |
| 945 | { | 947 | { |
| 946 | char *buffer = malloc(16); | ||
| 947 | uint32_t bytes = 0; | 948 | uint32_t bytes = 0; |
| 948 | uint64_t op = htole64(operation); | 949 | struct { |
| 950 | uint64_t handle; | ||
| 951 | uint64_t op; | ||
| 952 | } lockinfo; | ||
| 949 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; | 953 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; |
| 950 | 954 | ||
| 951 | if (!client || (handle == 0)) | 955 | if (!client || (handle == 0)) |
| @@ -956,12 +960,9 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op | |||
| 956 | debug_info("file handle %i", handle); | 960 | debug_info("file handle %i", handle); |
| 957 | 961 | ||
| 958 | /* Send command */ | 962 | /* Send command */ |
| 959 | memcpy(buffer, &handle, sizeof(uint64_t)); | 963 | lockinfo.handle = handle; |
| 960 | memcpy(buffer + 8, &op, 8); | 964 | lockinfo.op = htole64(operation); |
| 961 | 965 | ret = afc_dispatch_packet(client, AFC_OP_FILE_LOCK, (const char*)&lockinfo, sizeof(lockinfo), NULL, 0, &bytes); | |
| 962 | ret = afc_dispatch_packet(client, AFC_OP_FILE_LOCK, buffer, 16, NULL, 0, &bytes); | ||
| 963 | free(buffer); | ||
| 964 | buffer = NULL; | ||
| 965 | 966 | ||
| 966 | if (ret != AFC_E_SUCCESS) { | 967 | if (ret != AFC_E_SUCCESS) { |
| 967 | afc_unlock(client); | 968 | afc_unlock(client); |
| @@ -988,10 +989,12 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op | |||
| 988 | */ | 989 | */ |
| 989 | afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) | 990 | afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) |
| 990 | { | 991 | { |
| 991 | char *buffer = (char *) malloc(sizeof(char) * 24); | ||
| 992 | int64_t offset_loc = (int64_t)htole64(offset); | ||
| 993 | uint64_t whence_loc = htole64(whence); | ||
| 994 | uint32_t bytes = 0; | 992 | uint32_t bytes = 0; |
| 993 | struct { | ||
| 994 | uint64_t handle; | ||
| 995 | uint64_t whence; | ||
| 996 | int64_t offset; | ||
| 997 | } seekinfo; | ||
| 995 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; | 998 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; |
| 996 | 999 | ||
| 997 | if (!client || (handle == 0)) | 1000 | if (!client || (handle == 0)) |
| @@ -1000,12 +1003,10 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, | |||
| 1000 | afc_lock(client); | 1003 | afc_lock(client); |
| 1001 | 1004 | ||
| 1002 | /* Send the command */ | 1005 | /* Send the command */ |
| 1003 | memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */ | 1006 | seekinfo.handle = handle; |
| 1004 | memcpy(buffer + 8, &whence_loc, sizeof(uint64_t)); /* fromwhere */ | 1007 | seekinfo.whence = htole64(whence); |
| 1005 | memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); /* offset */ | 1008 | seekinfo.offset = (int64_t)htole64(offset); |
| 1006 | ret = afc_dispatch_packet(client, AFC_OP_FILE_SEEK, buffer, 24, NULL, 0, &bytes); | 1009 | ret = afc_dispatch_packet(client, AFC_OP_FILE_SEEK, (const char*)&seekinfo, sizeof(seekinfo), NULL, 0, &bytes); |
| 1007 | free(buffer); | ||
| 1008 | buffer = NULL; | ||
| 1009 | 1010 | ||
| 1010 | if (ret != AFC_E_SUCCESS) { | 1011 | if (ret != AFC_E_SUCCESS) { |
| 1011 | afc_unlock(client); | 1012 | afc_unlock(client); |
| @@ -1076,9 +1077,11 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi | |||
| 1076 | */ | 1077 | */ |
| 1077 | afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) | 1078 | afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) |
| 1078 | { | 1079 | { |
| 1079 | char *buffer = (char *) malloc(sizeof(char) * 16); | ||
| 1080 | uint32_t bytes = 0; | 1080 | uint32_t bytes = 0; |
| 1081 | uint64_t newsize_loc = htole64(newsize); | 1081 | struct { |
| 1082 | uint64_t handle; | ||
| 1083 | uint64_t newsize; | ||
| 1084 | } truncinfo; | ||
| 1082 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; | 1085 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; |
| 1083 | 1086 | ||
| 1084 | if (!client || (handle == 0)) | 1087 | if (!client || (handle == 0)) |
| @@ -1087,11 +1090,9 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new | |||
| 1087 | afc_lock(client); | 1090 | afc_lock(client); |
| 1088 | 1091 | ||
| 1089 | /* Send command */ | 1092 | /* Send command */ |
| 1090 | memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */ | 1093 | truncinfo.handle = handle; |
| 1091 | memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); /* newsize */ | 1094 | truncinfo.newsize = htole64(newsize); |
| 1092 | ret = afc_dispatch_packet(client, AFC_OP_FILE_SET_SIZE, buffer, 16, NULL, 0, &bytes); | 1095 | ret = afc_dispatch_packet(client, AFC_OP_FILE_SET_SIZE, (const char*)&truncinfo, sizeof(truncinfo), NULL, 0, &bytes); |
| 1093 | free(buffer); | ||
| 1094 | buffer = NULL; | ||
| 1095 | 1096 | ||
| 1096 | if (ret != AFC_E_SUCCESS) { | 1097 | if (ret != AFC_E_SUCCESS) { |
| 1097 | afc_unlock(client); | 1098 | afc_unlock(client); |
