8057eec38363b0ffcebb1cfc05a5e8e425637824
6 utils_strsep(char **stringp
, const char *delim
)
11 if (*stringp
== NULL
) {
16 strptr
= strstr(*stringp
, delim
);
22 *stringp
= strptr
+strlen(delim
);
27 utils_read_file(char **dst
, const char *filename
)
34 /* Open stream for reading */
35 stream
= fopen(filename
, "rb");
40 /* Find out file size */
41 fseek(stream
, 0, SEEK_END
);
42 filesize
= ftell(stream
);
43 fseek(stream
, 0, SEEK_SET
);
45 /* Allocate one extra byte for zero */
46 buffer
= malloc(filesize
+1);
52 /* Read data in a loop to buffer */
55 int ret
= fread(buffer
+read_bytes
, 1,
56 filesize
-read_bytes
, stream
);
61 } while (read_bytes
< filesize
);
63 /* Add final null byte and close stream */
64 buffer
[read_bytes
] = '\0';
67 /* If read didn't finish, return error */
68 if (read_bytes
!= filesize
) {
79 utils_hwaddr_raop(char *str
, int strlen
, const char *hwaddr
, int hwaddrlen
)
83 /* Check that our string is long enough */
84 if (strlen
== 0 || strlen
< 2*hwaddrlen
+1)
87 /* Convert hardware address to hex string */
88 for (i
=0,j
=0; i
<hwaddrlen
; i
++) {
89 int hi
= (hwaddr
[i
]>>4) & 0x0f;
90 int lo
= hwaddr
[i
] & 0x0f;
92 if (hi
< 10) str
[j
++] = '0' + hi
;
93 else str
[j
++] = 'A' + hi
-10;
94 if (lo
< 10) str
[j
++] = '0' + lo
;
95 else str
[j
++] = 'A' + lo
-10;
98 /* Add string terminator */
104 utils_hwaddr_airplay(char *str
, int strlen
, const char *hwaddr
, int hwaddrlen
)
108 /* Check that our string is long enough */
109 if (strlen
== 0 || strlen
< 2*hwaddrlen
+hwaddrlen
)
112 /* Convert hardware address to hex string */
113 for (i
=0,j
=0; i
<hwaddrlen
; i
++) {
114 int hi
= (hwaddr
[i
]>>4) & 0x0f;
115 int lo
= hwaddr
[i
] & 0x0f;
117 if (hi
< 10) str
[j
++] = '0' + hi
;
118 else str
[j
++] = 'a' + hi
-10;
119 if (lo
< 10) str
[j
++] = '0' + lo
;
120 else str
[j
++] = 'a' + lo
-10;
125 /* Add string terminator */