Debian Codegraph @

src/playlist.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2007, 2009 Moritz Grimm <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:412:9`!
18 # include "config.h"cxx . . $ `<file>/src/config.h`/
19 #endif
20
21 #include <sys/stat.h>
22 #ifdef HAVE_SYS_RANDOM_Hcxx . . $ `src/config.h:56:9`!
23 # include <sys/random.h>
24 #endif
25
26 #include <errno.h>
27 #include <limits.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <time.h>
32 #include <unistd.h>
33
34 #include "log.h"cxx . . $ `<file>/src/log.h`/
35 #include "playlist.h"cxx . . $ `<file>/src/playlist.h`/
36 #include "xalloc.h"cxx . . $ `<file>/src/xalloc.h`/
37
38 /* Usually defined in <sys/stat.h>. */
39 #ifndef S_IEXECcxx . . $ `<external>/531885356569766532/stat.h:177:10`!
40 # define S_IEXEC S_IXUSR
41 #endif /* !S_IEXEC */
42
43 struct playlistcxx . . $ playlist# {
44 char *filenamecxx . . $ playlist#filename.;
45 char **listcxx . . $ playlist#list.;
46 size_t sizecxx . . $ playlist#size.;
47 size_t numcxx . . $ playlist#num.;
48 size_t indexcxx . . $ playlist#index.;
49 int programcxx . . $ playlist#program.;
50 char *prog_trackcxx . . $ playlist#prog_track.;
51 };
52
53 static struct playlistcxx . . $ playlist# * _playlist_createcxx . . $ _playlist_create(ea32118fbd7a0ccc).(const char *);
54 static int _playlist_addcxx . . $ _playlist_add(a782fde374a10b12).(struct playlistcxx . . $ playlist# *, const char *);
55 static unsigned int _playlist_randomcxx . . $ _playlist_random(db52760e79bf9054).(void);
56 static const char * _playlist_run_programcxx . . $ _playlist_run_program(4a6773dfaf0af90e).(struct playlistcxx . . $ playlist# *);
57
58 static struct playlistcxx . . $ playlist# *
59 _playlist_createcxx . . $ _playlist_create(ea32118fbd7a0ccc).(const char *filename)
60 {
61 struct playlistcxx . . $ playlist# *pl;
62
63 pl = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*pl));
64 pl->filenamecxx . . $ playlist#filename. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(filename);
65
66 return (pl);
67 }
68
69 static int
70 _playlist_addcxx . . $ _playlist_add(a782fde374a10b12).(struct playlistcxx . . $ playlist# *pl, const char *entry)
71 {
72 size_t num;
73
74 num = pl->numcxx . . $ playlist#num. + 1;
75
76 if (pl->sizecxx . . $ playlist#size. == 0) {
77 pl->listcxx . . $ playlist#list. = xcalloccxx . . $ `src/xalloc.h:23:9`!(2UL, sizeof(char *));
78 pl->sizecxx . . $ playlist#size. = 2 * sizeof(char *);
79 }
80
81 if (pl->sizecxx . . $ playlist#size. / sizeof(char *) <= num) {
82 size_t i;
83
84 pl->listcxx . . $ playlist#list. = xreallocarraycxx . . $ `src/xalloc.h:24:9`!(pl->list, 2UL, pl->size);
85 pl->sizecxx . . $ playlist#size. = 2 * pl->sizecxx . . $ playlist#size.;
86
87 for (i = num; i < pl->sizecxx . . $ playlist#size. / sizeof(char *); i++)
88 pl->listcxx . . $ playlist#list.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
89 }
90
91 pl->listcxx . . $ playlist#list.[num - 1] = xstrdupcxx . . $ `src/xalloc.h:25:9`!(entry);
92 pl->numcxx . . $ playlist#num. = num;
93
94 return (1);
95 }
96
97 static unsigned int
98 _playlist_randomcxx . . $ _playlist_random(db52760e79bf9054).(void)
99 {
100 unsigned int ret = 0;
101
102 #ifdef HAVE_ARC4RANDOMcxx . . $ `src/config.h:5:9`!
103 ret = arc4randomcxx . . $ arc4random(db52760e79bf9054).();
104 #elif HAVE_GETRANDOM
105 if (sizeof(ret) != getrandom(&ret, sizeof(ret), 0)) {
106 log_alert("getrandom: %s", strerror(errno));
107 exit(1);
108 }
109 #else
110 # warning "using deterministic randomness for shuffling playlists"
111 ret = (unsigned int)random();
112 #endif
113
114 return (ret);
115 }
116
117 static const char *
118 _playlist_run_programcxx . . $ _playlist_run_program(4a6773dfaf0af90e).(struct playlistcxx . . $ playlist# *pl)
119 {
120 FILEcxx . . $ FILE# *filep;
121 char buf[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! + 1];
122
123 fflushcxx . . $ fflush(89bc1efcdac0ca22).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
124 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
125 log_debugcxx . . $ log_debug(581fddd72a8db8fc).("running command: %s", pl->filenamecxx . . $ playlist#filename.);
126 if ((filep = popencxx . . $ popen(82ec0787cd37e0a3).(pl->filenamecxx . . $ playlist#filename., "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
127 /* popen() does not set errno reliably ... */
128 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
129 log_errorcxx . . $ log_error(581fddd72a8db8fc).("execution error: %s: %s", pl->filenamecxx . . $ playlist#filename.,
130 strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
131 else
132 log_errorcxx . . $ log_error(581fddd72a8db8fc).("execution error: %s", pl->filenamecxx . . $ playlist#filename.);
133 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
134 }
135
136 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, (int)sizeof(buf), filep)) {
137 if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(filep))
138 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: output read error: %s", pl->filenamecxx . . $ playlist#filename.,
139 strerrorcxx . . $ strerror(ff224f080444ee45).(ferrorcxx . . $ ferror(89bc1efcdac0ca22).(filep)));
140 else
141 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: output read error: EOF", pl->filenamecxx . . $ playlist#filename.);
142 pclosecxx . . $ pclose(89bc1efcdac0ca22).(filep);
143 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
144 }
145 pclosecxx . . $ pclose(89bc1efcdac0ca22).(filep);
146
147 if (strlencxx . . $ strlen(751346f8406fd082).(buf) == sizeof(buf) - 1) {
148 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: output too long", pl->filenamecxx . . $ playlist#filename.);
149 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
150 }
151
152 buf[strcspncxx . . $ strcspn(335c1dc86f5c867f).(buf, "\n")] = '\0';
153 buf[strcspncxx . . $ strcspn(335c1dc86f5c867f).(buf, "\r")] = '\0';
154 if (buf[0] == '\0')
155 /* Empty line (end of playlist.) */
156 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
157
158 xfreecxx . . $ `src/xalloc.h:26:9`!(pl->prog_track);
159 pl->prog_trackcxx . . $ playlist#prog_track. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(buf);
160
161 return ((const char *)pl->prog_trackcxx . . $ playlist#prog_track.);
162 }
163
164 int
165 playlist_initcxx . . $ playlist_init(b126dc7c1de90089).(void)
166 {
167 srandomcxx . . $ srandom(cb2f890c2fdad230).((unsigned int)timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!));
168
169 return (0);
170 }
171
172 void playlist_exitcxx . . $ playlist_exit(49f6e7a06ebc5aa8).(void) {}
173
174 struct playlistcxx . . $ playlist# *
175 playlist_readcxx . . $ playlist_read(ea32118fbd7a0ccc).(const char *filename)
176 {
177 struct playlistcxx . . $ playlist# *pl;
178 unsigned long line;
179 FILEcxx . . $ FILE# *filep;
180 char buf[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
181
182 if (filename != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
183 pl = _playlist_createcxx . . $ _playlist_create(ea32118fbd7a0ccc).(filename);
184
185 if ((filep = fopencxx . . $ fopen(82ec0787cd37e0a3).(filename, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
186 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: %s", filename, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
187 playlist_freecxx . . $ playlist_free(d6737836562b4329).(&pl);
188 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
189 }
190 } else {
191 pl = _playlist_createcxx . . $ _playlist_create(ea32118fbd7a0ccc).("stdin");
192
193 if ((filep = fdopencxx . . $ fdopen(8f4e2d7350ebd077).(STDIN_FILENOcxx . . $ `<external>/12628407106812493757/unistd.h:210:9`!, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
194 log_errorcxx . . $ log_error(581fddd72a8db8fc).("stdin: %s", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
195 playlist_freecxx . . $ playlist_free(d6737836562b4329).(&pl);
196 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
197 }
198 }
199
200 line = 0;
201 while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, (int)sizeof(buf), filep) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
202 line++;
203
204 if (strlencxx . . $ strlen(751346f8406fd082).(buf) == sizeof(buf) - 1) {
205 char skip_buf[2];
206
207 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s[%lu]: file or path name too long",
208 pl->filenamecxx . . $ playlist#filename., line);
209 /* Discard any excess chars in that line. */
210 while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(skip_buf, (int)sizeof(skip_buf), filep) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
211 if (skip_buf[0] == '\n')
212 break;
213 }
214 continue;
215 }
216
217 /*
218 * fgets() would happily fill a buffer with
219 * { '\0', ..., '\n', '\0' }. Also skip lines that begin with
220 * a '#', which is considered a comment.
221 */
222 if (buf[0] == '\0' || buf[0] == '#')
223 continue;
224
225 /* Trim any trailing newlines and carriage returns. */
226 buf[strcspncxx . . $ strcspn(335c1dc86f5c867f).(buf, "\n")] = '\0';
227 buf[strcspncxx . . $ strcspn(335c1dc86f5c867f).(buf, "\r")] = '\0';
228
229 /* Skip lines that are empty after the trimming. */
230 if (buf[0] == '\0')
231 continue;
232
233 /* We got one. */
234 if (!_playlist_addcxx . . $ _playlist_add(a782fde374a10b12).(pl, buf)) {
235 fclosecxx . . $ fclose(89bc1efcdac0ca22).(filep);
236 playlist_freecxx . . $ playlist_free(d6737836562b4329).(&pl);
237 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
238 }
239 }
240 if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(filep)) {
241 log_errorcxx . . $ log_error(581fddd72a8db8fc).("playlist_read: %s: %s", pl->filenamecxx . . $ playlist#filename.,
242 strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
243 fclosecxx . . $ fclose(89bc1efcdac0ca22).(filep);
244 playlist_freecxx . . $ playlist_free(d6737836562b4329).(&pl);
245 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
246 }
247
248 fclosecxx . . $ fclose(89bc1efcdac0ca22).(filep);
249 return (pl);
250 }
251
252 struct playlistcxx . . $ playlist# *
253 playlist_programcxx . . $ playlist_program(ea32118fbd7a0ccc).(const char *filename)
254 {
255 struct playlistcxx . . $ playlist# *pl;
256 struct statcxx . . $ stat# st;
257
258 if (statcxx . . $ stat(a9cd1e23e96f423c).(filename, &st) == -1) {
259 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: %s", filename, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
260 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
261 }
262 if (st.st_modecxx . . $ stat#st_mode. & S_IWOTHcxx . . $ `<external>/531885356569766532/stat.h:187:9`!) {
263 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: world writeable", filename);
264 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
265 }
266 if (!(st.st_modecxx . . $ stat#st_mode. & (S_IEXECcxx . . $ `<external>/531885356569766532/stat.h:177:10`! | S_IXGRPcxx . . $ `<external>/531885356569766532/stat.h:182:9`! | S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!))) {
267 log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: not an executable program", filename);
268 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
269 }
270
271 pl = _playlist_createcxx . . $ _playlist_create(ea32118fbd7a0ccc).(filename);
272 pl->programcxx . . $ playlist#program. = 1;
273
274 return (pl);
275 }
276
277 void
278 playlist_freecxx . . $ playlist_free(d6737836562b4329).(struct playlistcxx . . $ playlist# **pl_p)
279 {
280 struct playlistcxx . . $ playlist# *pl;
281
282 if (pl_p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || (pl = *pl_p) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
283 return;
284
285 if (pl->filenamecxx . . $ playlist#filename. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
286 xfreecxx . . $ `src/xalloc.h:26:9`!(pl->filename);
287 pl->filenamecxx . . $ playlist#filename. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
288 }
289
290 if (pl->listcxx . . $ playlist#list. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
291 if (pl->sizecxx . . $ playlist#size. > 0) {
292 size_t i;
293
294 for (i = 0; i < pl->sizecxx . . $ playlist#size. / sizeof(char *); i++) {
295 if (pl->listcxx . . $ playlist#list.[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
296 xfreecxx . . $ `src/xalloc.h:26:9`!(pl->list[i]);
297 pl->listcxx . . $ playlist#list.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
298 } else
299 break;
300 }
301 }
302
303 xfreecxx . . $ `src/xalloc.h:26:9`!(pl->list);
304 }
305
306 if (pl->prog_trackcxx . . $ playlist#prog_track. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
307 xfreecxx . . $ `src/xalloc.h:26:9`!(pl->prog_track);
308 pl->prog_trackcxx . . $ playlist#prog_track. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
309 }
310
311 xfreecxx . . $ `src/xalloc.h:26:9`!(*pl_p);
312 *pl_p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
313 }
314
315 const char *
316 playlist_get_nextcxx . . $ playlist_get_next(4a6773dfaf0af90e).(struct playlistcxx . . $ playlist# *pl)
317 {
318 if (pl->programcxx . . $ playlist#program.)
319 return (_playlist_run_programcxx . . $ _playlist_run_program(4a6773dfaf0af90e).(pl));
320
321 if (pl->numcxx . . $ playlist#num. == 0)
322 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
323
324 return ((const char *)pl->listcxx . . $ playlist#list.[pl->indexcxx . . $ playlist#index.++]);
325 }
326
327 void
328 playlist_skip_nextcxx . . $ playlist_skip_next(fbb1db036548eb22).(struct playlistcxx . . $ playlist# *pl)
329 {
330 if (pl->programcxx . . $ playlist#program. || pl->numcxx . . $ playlist#num. == 0)
331 return;
332
333 if (pl->listcxx . . $ playlist#list.[pl->indexcxx . . $ playlist#index.] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
334 pl->indexcxx . . $ playlist#index.++;
335 }
336
337 unsigned long
338 playlist_get_num_itemscxx . . $ playlist_get_num_items(3834682fb383ec5a).(struct playlistcxx . . $ playlist# *pl)
339 {
340 if (pl->programcxx . . $ playlist#program.)
341 return (0);
342
343 return ((unsigned long)pl->numcxx . . $ playlist#num.);
344 }
345
346 unsigned long
347 playlist_get_positioncxx . . $ playlist_get_position(3834682fb383ec5a).(struct playlistcxx . . $ playlist# *pl)
348 {
349 if (pl->programcxx . . $ playlist#program.)
350 return (0);
351
352 return ((unsigned long)pl->indexcxx . . $ playlist#index.);
353 }
354
355 int
356 playlist_goto_entrycxx . . $ playlist_goto_entry(a782fde374a10b12).(struct playlistcxx . . $ playlist# *pl, const char *entry)
357 {
358 unsigned long i;
359
360 if (pl->programcxx . . $ playlist#program.)
361 return (0);
362
363 for (i = 0; i < pl->numcxx . . $ playlist#num.; i++) {
364 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(pl->listcxx . . $ playlist#list.[i], entry) == 0) {
365 pl->indexcxx . . $ playlist#index. = (size_t)i;
366 return (1);
367 }
368 }
369
370 return (0);
371 }
372
373 void
374 playlist_rewindcxx . . $ playlist_rewind(fbb1db036548eb22).(struct playlistcxx . . $ playlist# *pl)
375 {
376 if (pl->programcxx . . $ playlist#program.)
377 return;
378
379 pl->indexcxx . . $ playlist#index. = 0;
380 }
381
382 int
383 playlist_rereadcxx . . $ playlist_reread(47e6b14e38f59d9e).(struct playlistcxx . . $ playlist# **plist)
384 {
385 struct playlistcxx . . $ playlist# *new_pl, *pl;
386
387 pl = *plist;
388
389 if (pl->programcxx . . $ playlist#program.)
390 return (0);
391
392 if ((new_pl = playlist_readcxx . . $ playlist_read(ea32118fbd7a0ccc).(pl->filenamecxx . . $ playlist#filename.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
393 return (0);
394
395 playlist_freecxx . . $ playlist_free(d6737836562b4329).(&pl);
396 *plist = new_pl;
397
398 return (1);
399 }
400
401 /*
402 * Yet another implementation of the "Knuth Shuffle":
403 */
404 void
405 playlist_shufflecxx . . $ playlist_shuffle(fbb1db036548eb22).(struct playlistcxx . . $ playlist# *pl)
406 {
407 size_t d, i;
408 char *temp;
409
410 if (pl->programcxx . . $ playlist#program. || pl->numcxx . . $ playlist#num. < 2)
411 return;
412
413 for (i = 0; i < pl->numcxx . . $ playlist#num.; i++) {
414 size_t range;
415
416 range = pl->numcxx . . $ playlist#num. - i;
417
418 /*
419 * Only accept a random number if it is smaller than the
420 * largest multiple of our range. This reduces PRNG bias.
421 */
422 do {
423 d = (unsigned long)_playlist_randomcxx . . $ _playlist_random(db52760e79bf9054).();
424 } while (d > RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:91:9`! - (RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:91:9`! % range));
425
426 /*
427 * The range starts at the item we want to shuffle, excluding
428 * already shuffled items.
429 */
430 d = i + (d % range);
431
432 temp = pl->listcxx . . $ playlist#list.[d];
433 pl->listcxx . . $ playlist#list.[d] = pl->listcxx . . $ playlist#list.[i];
434 pl->listcxx . . $ playlist#list.[i] = temp;
435 }
436 }