Skip to content

Commit a791aca

Browse files
committed
More const
1 parent 0212409 commit a791aca

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/camlib.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,20 @@ PUB int ptp_check_prop(struct PtpRuntime *r, int code);
285285
PUB int ptp_buffer_resize(struct PtpRuntime *r, size_t size);
286286

287287
// Data structure functions
288-
PUB int ptp_write_unicode_string(char *dat, char *string);
288+
PUB int ptp_write_unicode_string(char *dat, const char *string);
289289
PUB int ptp_read_unicode_string(char *buffer, char *dat, int max);
290290
PUB int ptp_read_utf8_string(void *dat, char *string, int max);
291291
PUB int ptp_read_string(uint8_t *dat, char *string, int max);
292-
PUB int ptp_write_string(uint8_t *dat, char *string);
293-
PUB int ptp_write_utf8_string(void *dat, char *string);
294-
PUB int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length);
292+
PUB int ptp_write_string(uint8_t *dat, const char *string);
293+
PUB int ptp_write_utf8_string(void *dat, const char *string);
294+
PUB int ptp_read_uint16_array(const uint8_t *dat, uint16_t *buf, int max, int *length);
295295
PUB int ptp_read_uint16_array_s(uint8_t *bs, uint8_t *be, uint16_t *buf, int max, int *length);
296296
inline static int ptp_write_u8 (void *buf, uint8_t out) { ((uint8_t *)buf)[0] = out; return 1; }
297297
inline static int ptp_write_u16(void *buf, uint16_t out) { ((uint16_t *)buf)[0] = out; return 2; }
298298
inline static int ptp_write_u32(void *buf, uint32_t out) { ((uint32_t *)buf)[0] = out; return 4; }
299-
inline static int ptp_read_u32 (void *buf, uint32_t *out) { *out = ((uint32_t *)buf)[0]; return 4; }
300-
inline static int ptp_read_u16 (void *buf, uint16_t *out) { *out = ((uint16_t *)buf)[0]; return 2; }
301-
inline static int ptp_read_u8 (void *buf, uint8_t *out) { *out = ((uint8_t *)buf)[0]; return 1; }
299+
inline static int ptp_read_u32 (const void *buf, uint32_t *out) { *out = ((const uint32_t *)buf)[0]; return 4; }
300+
inline static int ptp_read_u16 (const void *buf, uint16_t *out) { *out = ((const uint16_t *)buf)[0]; return 2; }
301+
inline static int ptp_read_u8 (const void *buf, uint8_t *out) { *out = ((const uint8_t *)buf)[0]; return 1; }
302302

303303
// Build a new PTP/IP or PTP/USB command packet in r->data
304304
int ptp_new_cmd_packet(struct PtpRuntime *r, struct PtpCommand *cmd);

src/libwpd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int ptp_comm_init(struct PtpRuntime *r) {
1616
r->max_packet_size = 512;
1717

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

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

src/packet.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int ptp_read_string(uint8_t *d, char *string, int max) {
3939
return of;
4040
}
4141

42-
int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length) {
42+
int ptp_read_uint16_array(const uint8_t *dat, uint16_t *buf, int max, int *length) {
4343
int of = 0;
4444

4545
uint32_t n;
@@ -49,7 +49,7 @@ int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length) {
4949
if (i >= max) {
5050
ptp_panic("ptp_read_uint16_array overflow\n");
5151
} else {
52-
of += ptp_read_u16(buf + of, &buf[i]);
52+
of += ptp_read_u16(dat + of, &buf[i]);
5353
}
5454
}
5555

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

7575
// Write standard PTP wchar string
76-
int ptp_write_string(uint8_t *dat, char *string) {
76+
int ptp_write_string(uint8_t *dat, const char *string) {
7777
int of = 0;
7878

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

9090
// Write normal UTF-8 string
91-
int ptp_write_utf8_string(void *dat, char *string) {
91+
int ptp_write_utf8_string(void *dat, const char *string) {
9292
char *o = (char *)dat;
9393
int x = 0;
9494
while (string[x] != '\0') {
@@ -102,7 +102,7 @@ int ptp_write_utf8_string(void *dat, char *string) {
102102
}
103103

104104
// Write null-terminated UTF16 string
105-
int ptp_write_unicode_string(char *dat, char *string) {
105+
int ptp_write_unicode_string(char *dat, const char *string) {
106106
int i;
107107
for (i = 0; string[i] != '\0'; i++) {
108108
dat[i * 2] = string[i];

src/transport.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Packet transport interface for PTPUSB, PTPIP, and PTPUSBIP - uses OS IO functions
22
// Don't include this file with Windows/LibWPD builds. LibWPD replaces this file.
33

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

66
#include <stdio.h>
77
#include <stdint.h>
@@ -10,7 +10,6 @@
1010

1111
#include <camlib.h>
1212

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

0 commit comments

Comments
 (0)