Skip to content

Commit

Permalink
More const
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Sep 14, 2024
1 parent 0212409 commit a791aca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/camlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,20 @@ PUB int ptp_check_prop(struct PtpRuntime *r, int code);
PUB int ptp_buffer_resize(struct PtpRuntime *r, size_t size);

// Data structure functions
PUB int ptp_write_unicode_string(char *dat, char *string);
PUB int ptp_write_unicode_string(char *dat, const char *string);
PUB int ptp_read_unicode_string(char *buffer, char *dat, int max);
PUB int ptp_read_utf8_string(void *dat, char *string, int max);
PUB int ptp_read_string(uint8_t *dat, char *string, int max);
PUB int ptp_write_string(uint8_t *dat, char *string);
PUB int ptp_write_utf8_string(void *dat, char *string);
PUB int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length);
PUB int ptp_write_string(uint8_t *dat, const char *string);
PUB int ptp_write_utf8_string(void *dat, const char *string);
PUB int ptp_read_uint16_array(const uint8_t *dat, uint16_t *buf, int max, int *length);
PUB int ptp_read_uint16_array_s(uint8_t *bs, uint8_t *be, uint16_t *buf, int max, int *length);
inline static int ptp_write_u8 (void *buf, uint8_t out) { ((uint8_t *)buf)[0] = out; return 1; }
inline static int ptp_write_u16(void *buf, uint16_t out) { ((uint16_t *)buf)[0] = out; return 2; }
inline static int ptp_write_u32(void *buf, uint32_t out) { ((uint32_t *)buf)[0] = out; return 4; }
inline static int ptp_read_u32 (void *buf, uint32_t *out) { *out = ((uint32_t *)buf)[0]; return 4; }
inline static int ptp_read_u16 (void *buf, uint16_t *out) { *out = ((uint16_t *)buf)[0]; return 2; }
inline static int ptp_read_u8 (void *buf, uint8_t *out) { *out = ((uint8_t *)buf)[0]; return 1; }
inline static int ptp_read_u32 (const void *buf, uint32_t *out) { *out = ((const uint32_t *)buf)[0]; return 4; }
inline static int ptp_read_u16 (const void *buf, uint16_t *out) { *out = ((const uint16_t *)buf)[0]; return 2; }
inline static int ptp_read_u8 (const void *buf, uint8_t *out) { *out = ((const uint8_t *)buf)[0]; return 1; }

// Build a new PTP/IP or PTP/USB command packet in r->data
int ptp_new_cmd_packet(struct PtpRuntime *r, struct PtpCommand *cmd);
Expand Down
2 changes: 1 addition & 1 deletion src/libwpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int ptp_comm_init(struct PtpRuntime *r) {
r->max_packet_size = 512;

// in libwpd, this will only coinitalize this thread.
wpd_init(1, L"Camlib WPD");
wpd_init(0, L"Camlib WPD");

if (r->comm_backend != NULL) return 0;

Expand Down
10 changes: 5 additions & 5 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int ptp_read_string(uint8_t *d, char *string, int max) {
return of;
}

int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length) {
int ptp_read_uint16_array(const uint8_t *dat, uint16_t *buf, int max, int *length) {
int of = 0;

uint32_t n;
Expand All @@ -49,7 +49,7 @@ int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length) {
if (i >= max) {
ptp_panic("ptp_read_uint16_array overflow\n");
} else {
of += ptp_read_u16(buf + of, &buf[i]);
of += ptp_read_u16(dat + of, &buf[i]);
}
}

Expand All @@ -73,7 +73,7 @@ int ptp_read_uint16_array_s(uint8_t *bs, uint8_t *be, uint16_t *buf, int max, in
}

// Write standard PTP wchar string
int ptp_write_string(uint8_t *dat, char *string) {
int ptp_write_string(uint8_t *dat, const char *string) {
int of = 0;

uint32_t length = strlen(string);
Expand All @@ -88,7 +88,7 @@ int ptp_write_string(uint8_t *dat, char *string) {
}

// Write normal UTF-8 string
int ptp_write_utf8_string(void *dat, char *string) {
int ptp_write_utf8_string(void *dat, const char *string) {
char *o = (char *)dat;
int x = 0;
while (string[x] != '\0') {
Expand All @@ -102,7 +102,7 @@ int ptp_write_utf8_string(void *dat, char *string) {
}

// Write null-terminated UTF16 string
int ptp_write_unicode_string(char *dat, char *string) {
int ptp_write_unicode_string(char *dat, const char *string) {
int i;
for (i = 0; string[i] != '\0'; i++) {
dat[i * 2] = string[i];
Expand Down
4 changes: 1 addition & 3 deletions src/transport.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Packet transport interface for PTPUSB, PTPIP, and PTPUSBIP - uses OS IO functions
// Don't include this file with Windows/LibWPD builds. LibWPD replaces this file.

// Copyright 2022 by Daniel C (https://github.com/petabyt/camlib)
// Copyright 2024 by Daniel C (https://github.com/petabyt/camlib)

#include <stdio.h>
#include <stdint.h>
Expand All @@ -10,7 +10,6 @@

#include <camlib.h>

__attribute__((weak))
int ptpusb_send_bulk_packets(struct PtpRuntime *r, int length) {
int sent = 0;
int x;
Expand Down Expand Up @@ -178,7 +177,6 @@ int ptpip_write_packet(struct PtpRuntime *r, int of) {
// until we don't, then packet is over. This makes the code simpler and gives a reduces
// calls to the backend, which increases performance. This isn't possible with sockets -
// the read will time out in most cases.
__attribute__((weak))
int ptpusb_read_all_packets(struct PtpRuntime *r) {
int read = 0;

Expand Down

0 comments on commit a791aca

Please sign in to comment.