1 #include "scheduled.h"
2 #include "bailout.h"
3 #include "error.h"
4 #include "str.h"
5 #include "byte.h"
6 #include "api_dir.h"
7 
8 /* load all the jobs from directory dn.
9  * fill "jobs" array with job file names, each one terminated by \0.
10  * add an additional \0 to the end of the list.
11  */
12 void
load_jobs(const char * dn,stralloc * jobs)13 load_jobs(const char *dn,stralloc *jobs)
14 {
15 	int count;
16 	unsigned int i,j;
17 	count=api_dir_read(jobs,dn);
18 	if (count==-1)
19 		xbailout(111,errno,"failed to read ",dn,0,0);
20 
21 	/* XXX breaks api_dir encapsulation */
22 	for (i=0,j=0;i<jobs->len;) {
23 		struct jobinfo ji;
24 		unsigned int l;
25 		char *s;
26 		s=jobs->s+i;
27 		l=str_len(s)+1;
28 		if (parse_job(s,&ji)) {
29 			if (i!=j)
30 				byte_copy(jobs->s+j,l,s);
31 			j+=l;
32 		}
33 		i+=l;
34 	}
35 	jobs->len=j;
36 	if (!stralloc_0(jobs)) oom();
37 }
38