Skeleton * create_skeleton () { Skeleton *skeleton; skeleton = (Skeleton *) malloc (sizeof (Skeleton)); if (!skeleton) return NULL; skeleton -> surface_lst = lst_create (); skeleton -> nb_of_surfaces = 0; skeleton -> ext_image_lst = lst_create (); skeleton -> nb_of_ext_images = 0; return skeleton; }
/* * convert a java array of className objects to a sqm_lst_t list. * each element is converted from Java to C using j2c function. */ sqm_lst_t * jarray2lst(JNIEnv *env, jobjectArray jarr, char *className, void * (*j2c)(JNIEnv *, jobject)) { sqm_lst_t *lst; int idx, n; if (NULL == jarr) { PTRACE(1, "jni:NULL array passed to jarray2lst()"); return (NULL); } n = (int)(*env)->GetArrayLength(env, jarr); PTRACE(2, "jni:jarray2lst(jarr[%d],%s)", n, className); lst = lst_create(); for (idx = 0; idx < n; idx++) if (-1 == lst_append(lst, j2c(env, (*env)->GetObjectArrayElement(env, jarr, idx)))) { lst_free(lst); lst = NULL; break; } PTRACE(2, "jni:jarray2lst() done"); return (lst); }
/* * setup static information required for parser run. */ static int init_static_variables(void) { Trace(TR_DEBUG, "initializing static variables"); noEnd = NULL; file_required = B_FALSE; if (error_list != NULL) { lst_free_deep(error_list); } error_list = lst_create(); if (error_list == NULL) { Trace(TR_DEBUG, "initializing static variables failed: %s", samerrmsg); return (-1); } no_cmd_file = B_FALSE; empty_cmd_file = B_FALSE; Trace(TR_DEBUG, "initialized static variables"); return (0); }
/* * convert a jintArray to a C list of int */ sqm_lst_t * jintArray2lst(JNIEnv *env, jintArray jintArr) { sqm_lst_t *lst; int idx, len, *i; jint *p; if (NULL == jintArr) { PTRACE(1, "jni:NULL array passed to jintArray2lst()"); return (NULL); } len = (int)(*env)->GetArrayLength(env, jintArr); p = (jint *) malloc(len * sizeof (jint)); PTRACE(2, "jni:jintArray2lst(jintArr[%d])", len); lst = lst_create(); (*env)->GetIntArrayRegion(env, jintArr, 0, len, p); for (idx = 0; idx < len; idx++) { i = (int *)malloc(sizeof (int)); *i = (int)p[idx]; if (-1 == lst_append(lst, i)) { lst_free(lst); lst = NULL; break; } } free(p); PTRACE(2, "jni:jintArray2lst() done"); return (lst); }
int main(){ ElemType userVal; printf("Please enter a set of integers.\n"); int checker; LIST* lst = lst_create(); while (1){ checker = scanf("%i", &userVal); if (checker == EOF || checker == 0) break; lst_push_back(lst, userVal); } printf("The list before the quick sort: \n"); lst_print(lst); printf("The list after the quick sort: \n"); qsort1(lst); lst_print(lst); lst_free(lst); return 0; }
/* Get details about a file. */ int get_file_details( ctx_t *c, /* ARGSUSED */ char *fsname, sqm_lst_t *files, sqm_lst_t **status) { int rval, mntfd; node_t *fil; char mountpt[MAXPATHLEN+1]; char details[MAXPATHLEN+1]; struct stat64 sout; char *filstat; if (strlen(fsname) != 0) { rval = getfsmountpt(fsname, mountpt, sizeof (mountpt)); if (rval != 0) { return (rval); } } else { /* No FS specified, use root */ strlcpy(mountpt, "/", sizeof (mountpt)); } mntfd = open64(mountpt, O_RDONLY); if (mntfd < 0) return (samrerr(SE_NOT_A_DIR, mountpt)); *status = lst_create(); /* Return results in this list */ if (*status == NULL) { close(mntfd); return (-1); /* If allocation failed, samerr is set */ } fil = files->head; /* Walk through list of files */ while (fil != NULL) { memset(&sout, 0, sizeof (sout)); rval = fstatat64(mntfd, fil->data, &sout, 0); if (rval) { filstat = copystr(""); /* File doesn't exist */ } else { snprintf( details, sizeof (details), "size=%lld,created=%lu,modified=%lu", sout.st_size, sout.st_ctim.tv_sec, sout.st_mtim.tv_sec); filstat = copystr(details); } lst_append(*status, filstat); fil = fil->next; /* And check next file */ } close(mntfd); return (0); }
/* * get trace information of all SAM-daemon trace files * * Returns a list of formatted strings * * name=name, * procname=process name, * type=Log/Trace, * state=on/off, * path=filename, * flags=flags, * size=size, * modtime=last modified time (num of seconds since 1970) * */ int get_daemontrace_info(sqm_lst_t **lst_trace) { char buffer[BUFSIZ] = {0}; int tid = 0; int chars = 0; struct stat statbuf; struct TraceCtlBin *tb = NULL; /* * 1) Trace files * attach to TraceCtl.bin. * get the state(on/off), path, size and last modified time */ *lst_trace = lst_create(); tb = MapFileAttach(TRACECTL_BIN, TRACECTL_MAGIC, O_RDONLY); for (tid = 1 /* starts with 1 */; (tb != NULL && tid < TI_MAX); tid++) { struct TraceCtlEntry *tc; tc = &tb->entry[tid]; chars = snprintf(buffer, sizeof (buffer), "%s=%s, %s=%s, %s=%s", KEY_NAME, GetCustMsg(traceNames[tid].captionId), KEY_PROCNAME, traceNames[tid].processName, KEY_TYPE, GetCustMsg(SE_TYPE_TRACE)); ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%s", KEY_STATE, (*tc->TrFname == '\0') ? STATE_OFF : STATE_ON); if (*tc->TrFname != '\0') { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%s, %s=%s", KEY_PATH, tc->TrFname, KEY_FLAGS, TraceGetOptions(tc, NULL, 0)); /* to get the modification time, stat the file */ if (stat(tc->TrFname, &statbuf) == 0) { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%ld, %s=%lu", KEY_SIZE, statbuf.st_size, KEY_MODTIME, statbuf.st_mtime); } } lst_append(*lst_trace, strdup(buffer)); } return (0); }
/* * get the status of all log and trace files in the SAM-FS configuration * This includes the Solaris system log, SAM system log, archiver logs, * device logs, releaser logs, stager logs, recycler logs, and daemon trace * status * * Return a list of formatted strings * * name=name, * type=Log/Trace, * state=on/off, * path=filename, * flags=flags, * size=size, * modtime=last modified time (num of seconds since 1970) */ int get_logntrace( ctx_t *ctx, /* ARGSUSED */ sqm_lst_t **lst /* return - list of formatted strings */ ) { char *info = NULL; sqm_lst_t *lst_log = NULL; if (ISNULL(lst) || ((*lst = lst_create()) == NULL)) { return (-1); } if (get_daemontrace_info(&lst_log) == 0) { lst_concat(*lst, lst_log); } if (get_samlog_lst(&lst_log) == 0) { lst_concat(*lst, lst_log); } if (get_filestat( SYSTEMLOG, SE_SOLARIS_SYSTEM_LOG_DESC, &info) == 0) { lst_append(*lst, info); } /* If QFS only install, do not display archive related logs */ if (get_samfs_type(NULL) != QFS) { if (get_devlog_info(&lst_log) == 0) { lst_concat(*lst, lst_log); } if (get_recyclelog_info(&info) == 0) { lst_append(*lst, info); } if (get_archivelog_info(&lst_log) == 0) { lst_concat(*lst, lst_log); } if (get_releaselog_info(&lst_log) == 0) { lst_concat(*lst, lst_log); } if (get_stagelog_info(&info) == 0) { lst_append(*lst, info); } /* * For now api_version 1.3.2, the restore log is hardcoded to * RESTORELOG = /var/opt/SUNWsamfs/restore.log */ if (get_filestat( RESTORELOG, SE_RESTORE_LOG_DESC, &info) == 0) { lst_append(*lst, info); } } return (0); }
int tbl_put(table_t *ct, connection_t *c) { int index = tbl_hash(c->client, c->server); if (ct->curr_size <= MAX_CONNECTIONS) { lst_add(ct->map[index], lst_create(c)); ct->curr_size++; return 0; } return 1; }
int list_activities( ctx_t *c, /* ARGSUSED */ int maxentries, /* Maximum number of strings to return */ char *rest, /* fnmatch pattern to exclude returns */ sqm_lst_t **activities) /* Returned list of descriptor strings */ { samrthread_t *ptr; char *bufptr; int rval; sqm_lst_t *l; char restrictions[MAXPATHLEN]; /* Fully wild-card selector */ if (rest != NULL) snprintf(restrictions, MAXPATHLEN, "*%s*", rest); else strlcpy(restrictions, "*", MAXPATHLEN); *activities = lst_create(); pthread_mutex_lock(samrlock); /* ++ LOCK samrtlist */ ptr = samrtlist; while ((ptr != NULL) && ((*activities)->length < maxentries)) { rval = ptr->details(ptr, &bufptr); /* Ask about a task */ if (rval == 0) { if (fnmatch(restrictions, bufptr, 0)) free(bufptr); /* Doesn't match */ else lst_append(*activities, bufptr); } ptr = ptr->next; } pthread_mutex_unlock(samrlock); /* ++ UNLOCK samrtlist */ /* get and append process jobs that match the restrictions */ if (get_process_jobs(NULL, rest, &l) != 0) { return (-1); } else if (l->length != 0) { if (lst_concat(*activities, l) != 0) { return (-1); } } return (0); }
void qsort1(LIST* lst){ if(lst_length(lst) <= 1) return; ElemType pivot = lst_pop_front(lst); LIST* pivotList = lst_create(); lst_push_front(pivotList, pivot); LIST* lst2 = lst_filter_leq(lst, pivot); qsort1(lst); qsort1(lst2); lst_concat(lst2, pivotList); lst_concat(lst2, lst); lst_concat(lst, lst2); }
static _linkage_block_ * init_linkage_block_ (Line *line, Surface *surface) { _linkage_block_ *linkage_block; assert (line); assert (surface); linkage_block = (_linkage_block_ *) malloc (sizeof (_linkage_block_)); if (!linkage_block) return 0; linkage_block -> candidate_line_lst = lst_create (); linkage_block -> line = line; linkage_block -> surface = surface; linkage_block -> nb_of_candidates = 0; return linkage_block; }
int get_file_status( ctx_t *c, /* ARGSUSED */ sqm_lst_t *filepaths, sqm_lst_t **filestatus) { int rval = 0; int filestat; node_t *node; struct stat64 sout; /* Buffer to receive file status */ *filestatus = lst_create(); /* Return results in this list */ if (*filestatus == NULL) return (-1); /* samerr is already set */ node = filepaths->head; while (node != NULL) { if (stat64(node->data, &sout)) { /* Ask about a file */ filestat = SAMR_MISSING; /* File doesn't even exist */ } else if ((sout.st_mode & S_IFMT) == S_IFDIR) { filestat = SAMR_DIRFILE; /* This is a directory */ } else if ((sout.st_mode & S_IFMT) == S_IFREG) { if (sout.st_size && (sout.st_blocks == 0)) filestat = SAMR_RELFILE; /* File not on disk */ else filestat = SAMR_REGFILE; /* Is file, on disk */ } else { filestat = SAMR_NOTFILE; /* Neither file nor dir. */ } rval = lst_append(*filestatus, copyint(filestat)); if (rval) break; node = node->next; } if (rval) lst_free_deep(*filestatus); return (rval); }
int main() { // Test values. LIST *empty = lst_create(); LIST *anotherEmptyList = lst_create(); LIST *one = lst_create(); // List of one element [ 5 ]. LIST *medium = lst_create(); // List of ten elements [ 1 2 ... 9 10 ]. LIST *evenList; // Lst of five even elements [ 2 4 6 8 10 ]. LIST *oddList; // List of five odd elements [ 1 3 5 7 9 ]. LIST *dupsOfevenList; // List of some even duplicate elements [ 4 8 12 16 20 ]. LIST *resultList; srand(time(NULL)); lst_push_back(one, 5); for(int i = 1; i <= 10; ++i) { lst_push_back(medium, i); } /** * Unit test for void lst_push_back(LIST *l, ElemType val); */ printf("\n\nTest: 0A\nDescription: Testing lst_push_back with List of length 0 with elements [] and val=42\nExpected output: [ 42 ]\n"); printf("Your output:"); lst_push_back(empty, 42); lst_print(empty); FREE(empty); empty = lst_create(); printf("\n\nTest: 0B\nDescription: Testing lst_push_back with List of length 1 with elements [ 5 ] and val=42\nExpected output: [ 5 42 ]\n"); printf("Your output:"); lst_push_back(one, 42); lst_print(one); FREE(one); one = lst_create(); lst_push_back(one, 5); // Reset one for later tests. evenList = lst_create(); for (int i=1; i<=5; ++i) { lst_push_back(evenList, i*2); } printf("\n\nTest: 0C\nDescription: Testing lst_push_back with List of length 5 with elements [2 4 6 8 10] and val=42\nExpected output: [ 2 4 6 8 10 42 ]\n"); printf("Your output:"); lst_push_back(evenList, 42); lst_print(evenList); FREE(evenList); /** * 2. Unit tests on function: int lst_count(LIST *l, ElemType x); */ printf("\n\nTest: 2A\nDescription: Testing lst_count with List of length 0 and x=5\nExpected output: 0\n"); printf("Your output: %d\n", lst_count(empty, 5)); printf("\n\nTest: 2B\nDescription: Testing lst_count with List of length 10 and x=-5\nExpected output: 0\n"); printf("Your output: %d\n", lst_count(medium, -5)); printf("\n\nTest: 2C\nDescription: Testing lst_count with List of length 10 and x=5\nExpected output: 1\n"); printf("Your output: %d\n", lst_count(medium, 5)); lst_push_front(medium, 10); printf("\n\nTest: 2D\nDescription: Testing lst_count with List of length 10 and x=10\nExpected output: 2\n"); printf("Your output: %d\n", lst_count(medium, 10)); lst_pop_front(medium); // Reset value for later tests. /** * 4. Unit tests on function: void lst_reverse(LIST *l); */ printf("\n\nTest: 4A\nDescription: Testing lst_reverse with List of length 0\nExpected output: []\n"); printf("Your output: "); lst_reverse(empty); lst_print(empty); printf("\n\nTest: 4B\nDescription: Testing lst_reverse with List of length 1\nExpected output: [ 5 ]\n"); printf("Your output: "); lst_reverse(one); lst_print(one); printf("\n\nTest: 4C\nDescription: Testing lst_reverse with List of length 10\nExpected output: [ 10 9 8 7 6 5 4 3 2 1 ]\n"); printf("Your output: "); lst_reverse(medium); lst_push_back(medium, 99); lst_pop_back(medium); // Check for tail correctness. lst_print(medium); FREE(medium); medium = lst_create(); for (int i=1; i<=10; ++i) { lst_push_back(medium, i); } // Reset value for later tests. /** * 6. Unit tests on void lst_insert_sorted(LIST *l, ElemType x); */ evenList = lst_create(); for(int i=1; i<=5; ++i) { lst_push_back(evenList, i*2); } printf("\n\nTest: 6A\nDescription: Testing lst_insert_sorted with List of length 0 and x=5\nExpected output: [ 5 ]\n"); printf("Your output: "); lst_insert_sorted(empty, 5); lst_print(empty); FREE(empty); empty = lst_create(); // Resets value for later tests. printf("\n\nTest: 6B\nDescription: Testing lst_insert_sorted with List of length 5 and x=5\nExpected output: [ 2 4 5 6 8 10 ]\n"); printf("Your output: "); lst_insert_sorted(evenList, 5); lst_print(evenList); FREE(evenList); evenList = lst_create(); for(int i=1; i<=5; ++i) { lst_push_back(evenList, i*2); } printf("\n\nTest: 6C\nDescription: Testing lst_insert_sorted with List of length 5 and x=0\nExpected output: [ 0 2 4 6 8 10 ]\n"); printf("Your output: " ); lst_insert_sorted(evenList, 0); lst_print(evenList); FREE(evenList); evenList = lst_create(); for(int i=1; i<=5; ++i) { lst_push_back(evenList, i*2); } printf("\n\nTest: 6D\nDescription: Testing lst_insert_sorted with List of length 5 and x=12\nExpected output: [ 2 4 6 8 10 12 ]\n"); printf("Your output: "); lst_insert_sorted(evenList, 12); lst_print(evenList); FREE(evenList); evenList = lst_create(); for(int i=1; i<=5; ++i) { lst_push_back(evenList, i*2); } // Reset value for later tests. /** * 8. Unit tests on void lst_merge_sorted(LIST *a, LIST *b); */ printf("\n\nTest: 8A\nDescription: Testing lst_merge_sorted with List a of length 0 with elements [] and List b of length 0 with elements []\n"); printf("Your output:"); lst_merge_sorted(anotherEmptyList, empty); lst_print(anotherEmptyList); FREE(anotherEmptyList); FREE(empty); empty = lst_create(); anotherEmptyList = lst_create(); printf("\n\nTest: 8B\nDescription: Testing lst_merge_sorted with List a of length 1 with elements [ 5 ] and List b of length 0 with elements []\n"); printf("\nExpected output: [ 5 ]\n"); printf("Your output: "); lst_merge_sorted(one, empty); lst_print(one); FREE(one); FREE(empty); one = lst_create(); empty = lst_create(); lst_push_back(one, 10); printf("\n\nTest: 8C\nDescription: Testing lst_merge_sorted with List a of length 0 with elements [] and List b of length 1 with elements [ 10 ]\n"); printf("\nExpected output: [ 10 ]\n"); printf("Your output: "); lst_merge_sorted(empty, one); lst_print(empty); FREE(empty); FREE(one); empty = lst_create(); one = lst_create(); lst_push_back(one, 5); oddList = lst_create(); for(int i=0; i<5; ++i) { lst_push_back(oddList, i*2+1); } printf("\n\nTest: 8D\nDescription: Testing lst_merge_sorted with List a of length 5 with elements [ 2 4 6 8 10 ] and List b of length 5 with elements [ 1 3 5 7 9 ]"); printf("\nExpected output: [ 1 2 3 4 5 6 7 8 9 10 ]\n"); printf("Your output: "); lst_merge_sorted(evenList, oddList); lst_print(evenList); FREE(evenList); FREE(oddList); evenList = lst_create(); dupsOfevenList = lst_create(); for (int i=1; i<=5; ++i) { lst_push_back(evenList, i*2); lst_push_back(dupsOfevenList, i*4); } printf("\n\nTest: 8E\nDescription: Testing lst_merge_sorted with List a of length 5 with elements [ 2 4 6 8 10 ] and List b of length 5 with elements [ 4 8 12 16 20 ]\n"); printf("\nExpected output: [ 2 4 4 6 8 8 10 12 16 20 ]\n"); printf("Your output: "); lst_merge_sorted(evenList, dupsOfevenList); lst_print(evenList); FREE(evenList); FREE(dupsOfevenList); /** * 10. Unit tests on LIST * lst_from_array(ElemType a[], int n); **/ int emptyArray[] = {}; int oneArray[] = {5}; int manyArray[] = {1,2,3,4,5}; printf("\n\nTest: 10A\nDescription: Testing lst_from_array with array of length 0 with elements [] and n=0\nExpected output: []\n"); printf("Your output:"); resultList = lst_from_array(emptyArray, 0); if (resultList) { lst_print(resultList); } else { printf("SEG FAULT. No List returned.\n"); } if (resultList) { FREE(resultList);} printf("\n\nTest: 10B\nDescription: Testing lst_from_array with Array of length 1 with elements [ 5 ] and n=1\nExpected output: [ 5 ]\n"); printf("Your output:"); resultList = lst_from_array(oneArray, 1); if (resultList) { lst_print(resultList); } else { printf("SEG FAULT. No List returned.\n"); } if (resultList) { FREE(resultList); } printf("\n\nTest: 10C\nDescription: Testing lst_from_array with Array of length 5 with elements [ 1 2 3 4 5 ] and n=5\nExpected output: [ 1 2 3 4 5 ]\n"); printf("Your output:"); resultList = lst_from_array(manyArray, 5); if (resultList) { lst_print(resultList); } else { printf("SEG FAULT. No List returned.\n"); } if (resultList) { FREE(resultList); } /** * 12. Unit tests for LIST * lst_prefix(LIST *lst, unsigned int k); */ printf("\n\nTest: 12A\nDescription: Testing lst_prefix with List of length 0 with elements [] and k=0\nExpected output: []\n"); printf("Expected return value: []"); printf("Your output:\n"); resultList = lst_prefix(empty, 0); lst_print(empty); printf("Your return value: "); if (resultList) { lst_print(resultList); } else { printf("SEG FAULT. No List returned.\n"); } if (resultList) { FREE(resultList); } FREE(empty); empty = lst_create(); printf("\n\nTest: 12B\nDescription: Testing lst_prefix with List of length 0 with elements [] and k=3\nExpected output: []\n"); printf("Expected return value: []\n"); printf("Your output:"); resultList = lst_prefix(empty, 3); lst_print(empty); printf("Your return value: "); if (resultList) { lst_print(resultList); } else { printf("SEG FAULT. No List returned.\n"); } if (resultList) { FREE(resultList); } FREE(empty); empty = lst_create(); printf("\n\nTest: 12C\nDescription: Testing lst_prefix with List of length 1 with elements [ 5 ] and k=0\nExpected output: [ 5 ]\n"); printf("Expected return value: []\n"); printf("Your output:"); resultList = lst_prefix(one, 0); lst_print(one); printf("Your return value: "); if (resultList) { lst_print(resultList); } else { printf("SEG FAULT. No List returned.\n"); } if (resultList) { FREE(resultList); } FREE(one); one = lst_create(); lst_push_back(one, 5); evenList = lst_create(); for(int i=1; i<=5; i++) { lst_push_back(evenList, i*2); } printf("\n\nTest: 12D\nDescription: Testing lst_prefix with List of length 5 with elements [ 2 4 6 8 10 ] and k=3\nExpected output: [ 8 10 ]\n"); printf("Expected return value: [ 2 4 6 ]\n"); printf("Your output: "); resultList = lst_prefix(evenList, 3); lst_print(evenList); printf("Your return value: "); if (resultList) { lst_print(resultList); } else { printf("SEG FAULT. No List returned.\n"); } if (resultList) { FREE(resultList); } //FREE(evenList); /** * 14. Unit test for void lst_concat(LIST *a, LIST *b); */ anotherEmptyList = lst_create(); evenList = lst_create(); oddList = lst_create(); for(int i=1; i<=5; i++) { lst_push_back(evenList, i*2); lst_push_back(oddList, i*2-1); } // 2 4 6 8 10 printf("\n\nTest: 14A\nDescription: Testing lst_concat with List a of length 0 with elements [] and List b of length 0 with elements []\nExpected output: []\n"); printf("Your output:"); lst_concat(anotherEmptyList, empty); lst_print(anotherEmptyList); FREE(anotherEmptyList); FREE(empty); empty = lst_create(); anotherEmptyList = lst_create(); printf("\n\nTest: 14B\nDescription: Testing lst_concat with List a of length 1 with elements [ 5 ] and List b of length 0 with elements []\nExpected output: [ 5 ]\n"); printf("Your output:"); lst_concat(one, anotherEmptyList); lst_print(one); FREE(one); FREE(anotherEmptyList); anotherEmptyList = lst_create(); one = lst_create(); lst_push_back(one, 10); printf("\n\nTest: 14C\nDescription: Testing lst_concat with List a of length 0 with elements []"); printf(" and List b of length 1 with elements [ 10 ]\nExpected output: [ 10 ]\n"); printf("Your output:"); lst_concat(anotherEmptyList, one); lst_print(anotherEmptyList); FREE(anotherEmptyList); FREE(one); one = lst_create(); lst_push_back(one, 5); printf("\n\nTest: 14D\nDescription: Testing lst_concat with List a of length 5 with elements [ 2 4 6 8 10]"); printf(" and List b of length 5 with elements [ 1 3 5 7 9 ]\nExpected output: [ 2 4 6 8 10 1 3 5 7 9 ]\n"); printf("Your output:"); lst_concat(evenList, oddList); lst_print(evenList); FREE(evenList); FREE(oddList); evenList = lst_create(); dupsOfevenList = lst_create(); for(int i=1; i<=5; ++i) { lst_push_back(evenList, i*2); lst_push_back(dupsOfevenList, i*4); } printf("\n\nTest: 14E\nDescription: Testing lst_concat with List a of length 5 with elements [ 2 4 6 8 10 ] and List b of length 5 with elements [ 4 8 12 16 20 ]\n" "Expected output: [ 2 4 6 8 10 4 8 12 16 20 ]\n"); printf("Your output:"); lst_concat(evenList, dupsOfevenList); lst_print(evenList); FREE(evenList); FREE(dupsOfevenList); }
int main (int argc, char **argv) { int dbug=0; char *input; int ch; list *l = lst_create(); if(argc ==2){ if(argv[1][0] == '-' && argv[1][1] == 'd'){ dbug = 1; // ./a.out -d printf("\nDebug mode activated\n"); } } printf ("Starting Restaurant Wait List Program\n\n"); printf ("Enter command: "); while ((ch = getNextNWSChar ()) != EOF) { /* check for the various commands */ if ('q' == ch) { printf ("Quitting Program\n"); return (0); } else if ('?' == ch) { printCommands(); } else if('a' == ch) { doAdd(l,dbug); } else if('c' == ch) { doCallAhead(l,dbug); } else if('w' == ch) { doWaiting(l,dbug); } else if('r' == ch) { doRetrieve(l,dbug); } else if('l' == ch) { doList(l,dbug); } else if('d' == ch) { doDisplay(l,dbug); } else { printf ("%c - in not a valid command\n", ch); printf ("For a list of valid commands, type ?\n"); clearToEoln(); } printf ("\nEnter command: "); } printf ("Quiting Program - EOF reached\n"); lst_free(l,dbug); return 1; }
/* * get log information for releaser (one log per file system) * * Returns a formatted string * * name=name, * type=Log/Trace, * state=on/off, * path=filename, * flags=flags, * size=size, * modtime=last modified time (num of seconds since 1970) */ int get_releaselog_info( sqm_lst_t **lst_releaselog ) { char buffer[BUFSIZ] = {0}; char global_log[128] = {0}; int chars = 0; sqm_lst_t *lst_rel_fs_dir = NULL; node_t *node_rel_fs_dir = NULL; rl_fs_directive_t *rel_fs_dir = NULL; struct stat statbuf; /* get releaser configuration */ if (get_all_rl_fs_directives(NULL, &lst_rel_fs_dir) == -1) { return (-1); } *lst_releaselog = lst_create(); /* initialize */ node_rel_fs_dir = lst_rel_fs_dir->head; for (node_rel_fs_dir = lst_rel_fs_dir->head; node_rel_fs_dir != NULL; node_rel_fs_dir = node_rel_fs_dir->next) { char releaser_log[128]; releaser_log[0] = '\0'; buffer[0] = '\0'; chars = 0; rel_fs_dir = (rl_fs_directive_t *)node_rel_fs_dir->data; /* * Get the global properties logfile * assume it would always be at the head of the list */ if (strcmp(rel_fs_dir->fs, GLOBAL) == 0) { strlcpy(global_log, rel_fs_dir->releaser_log, sizeof (global_log)); chars = snprintf(buffer, sizeof (buffer), "%s=%s, %s=%s, %s=%s", KEY_NAME, GetCustMsg(SE_RELEASE_GLOBAL_LOG_DESC), KEY_TYPE, GetCustMsg(SE_TYPE_LOG), KEY_STATE, (global_log[0] != '\0') ? STATE_ON : STATE_OFF); if (global_log[0] != '\0') { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%s", KEY_PATH, global_log); /* no flags ? */ if (stat(global_log, &statbuf) == 0) { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%ld, %s=%lu", KEY_SIZE, statbuf.st_size, KEY_MODTIME, statbuf.st_mtime); } } lst_append(*lst_releaselog, strdup(buffer)); continue; } else { /* not a global property logfile */ /* * If the file system does not have a release logfile * associated with it, skip */ if ((rel_fs_dir->releaser_log[0] != '\0') && (global_log[0] != '\0') && (strcmp(rel_fs_dir->releaser_log, global_log) != 0)) { /* logfile specific to file system */ chars = snprintf(buffer, sizeof (buffer), "%s=%s %s, %s=%s, %s=%s", KEY_NAME, GetCustMsg(SE_RELEASE_LOG_DESC), rel_fs_dir->fs, KEY_TYPE, GetCustMsg(SE_TYPE_LOG), KEY_STATE, (rel_fs_dir->releaser_log[0] != '\0') ? STATE_ON : STATE_OFF); if (rel_fs_dir->releaser_log[0] != '\0') { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%s", KEY_PATH, rel_fs_dir->releaser_log); /* no flags ? */ if (stat(rel_fs_dir->releaser_log, &statbuf) == 0) { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%ld, %s=%lu", KEY_SIZE, statbuf.st_size, KEY_MODTIME, statbuf.st_mtime); } } lst_append(*lst_releaselog, strdup(buffer)); } } } lst_free_deep(lst_rel_fs_dir); return (0); }
/* * get archiver log info, there is one archive log per file system * * Returns a formatted string * * name=name, * type=Log/Trace, * state=on/off, * path=filename, * flags=flags, * size=size, * modtime=last modified time (num of seconds since 1970) */ int get_archivelog_info( sqm_lst_t **lst_archivelog ) { ar_fs_directive_t *ar_fs_dir = NULL; ar_global_directive_t *ar_global = NULL; sqm_lst_t *lst_ar_fs_dir = NULL; node_t *node_ar_fs_dir = NULL; char buffer[BUFSIZ] = {0}; int chars = 0; struct stat statbuf; /* get all file system directives for archiving */ if (get_all_ar_fs_directives(NULL, &lst_ar_fs_dir) == -1) { return (-1); } /* get archiver log global directive */ if (get_ar_global_directive(NULL, &ar_global) == -1) { lst_free_deep_typed(lst_ar_fs_dir, FREEFUNCCAST(free_ar_fs_directive)); return (-1); } *lst_archivelog = lst_create(); /* add the global archive directive */ chars = snprintf(buffer, sizeof (buffer), "%s=%s, %s=%s, %s=%s", KEY_NAME, GetCustMsg(SE_ARCHIVE_GLOBAL_LOG_DESC), KEY_TYPE, GetCustMsg(SE_TYPE_LOG), KEY_STATE, (ar_global->log_path[0] != '\0') ? STATE_ON : STATE_OFF); if (ar_global->log_path[0] != '\0') { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%s", KEY_PATH, ar_global->log_path); if (stat(ar_global->log_path, &statbuf) == 0) { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%ld, %s=%lu", KEY_SIZE, statbuf.st_size, KEY_MODTIME, statbuf.st_mtime); } } lst_append(*lst_archivelog, strdup(buffer)); /* now check if any filesystems have overloaded the global log */ node_ar_fs_dir = lst_ar_fs_dir->head; while (node_ar_fs_dir != NULL) { ar_fs_dir = (ar_fs_directive_t *)node_ar_fs_dir->data; buffer[0] = '\0'; chars = 0; if ((ar_fs_dir != NULL) && strcmp(ar_global->log_path, ar_fs_dir->log_path)) { /* Get the fsname and the logpath */ chars = snprintf(buffer, sizeof (buffer), "%s=%s %s, %s=%s, %s=%s", KEY_NAME, GetCustMsg(SE_ARCHIVE_LOG_DESC), ar_fs_dir->fs_name, KEY_TYPE, GetCustMsg(SE_TYPE_LOG), KEY_STATE, (ar_fs_dir->log_path[0] != '\0') ? STATE_ON : STATE_OFF); if (ar_fs_dir->log_path[0] != '\0') { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%s", KEY_PATH, ar_fs_dir->log_path); if (stat(ar_fs_dir->log_path, &statbuf) == 0) { ADD_DELIM(chars, buffer); chars += snprintf(buffer + chars, sizeof (buffer) - chars, "%s=%ld, %s=%lu", KEY_SIZE, statbuf.st_size, KEY_MODTIME, statbuf.st_mtime); } } lst_append(*lst_archivelog, strdup(buffer)); } buffer[0] = '\0'; chars = 0; node_ar_fs_dir = node_ar_fs_dir->next; } lst_free_deep_typed(lst_ar_fs_dir, FREEFUNCCAST(free_ar_fs_directive)); free_ar_global_directive(ar_global); return (0); }
/* * get SAM system log information * * Information is a list of formatted strings * * name=name, * type=Log/Trace, * state=on/off, * path=filename, * flags=flags, * size=size, * modtime=last modified time (num of seconds since 1970) */ int get_samlog_lst( sqm_lst_t **lst_log ) { sam_defaults_t *sam_defaults = NULL; char *log_keyword = NULL; char *flags = NULL; FILE *fp = NULL; char linebuf[BUFSIZ]; char buffer[4096]; /* log facility from defaults is an int, convert to syslog facility */ if ((sam_defaults = GetDefaults()) == NULL) { Trace(TR_ERR, "Could not get sam log config"); return (-1); } log_keyword = ifacility2sfacility(sam_defaults->log_facility); if (log_keyword == NULL) { Trace(TR_ERR, "Unrecognized system facility for sam log"); return (-1); } if ((fp = fopen(SYSLOG_CONF, "r")) == NULL) { return (-1); } *lst_log = lst_create(); /* * res_stream format:facility.level [ ; facility.level ]<tab>action * * there can be multiple lines with this facility * e.g. * local7.debug /var/adm/sam-debug * local7.warn /var/adm/sam-warn * local7.crit /var/adm/sam-crit */ while (fgets(linebuf, BUFSIZ, fp)) { linebuf[BUFSIZ - 1] = '\0'; char *lptr = linebuf; /* ignore whitespaces, empty lines and comments */ lptr += strspn(lptr, WHITESPACE); if (lptr[0] == CHAR_POUND) { continue; } if (strstr(lptr, log_keyword) == NULL) { continue; } char *facility = NULL, *action = NULL, *lasts = NULL; if ((facility = strtok_r(lptr, WHITESPACE, &lasts)) != NULL) { action = strtok_r(NULL, WHITESPACE, &lasts); } if (facility == NULL || action == NULL) { /* ignore */ continue; } Trace(TR_MISC, "facility=%s, action=%s", facility, action); char *keyword = NULL; flags = NULL; lasts = NULL; /* tokenize facility to get keyword and flag */ if ((keyword = strtok_r(facility, COLON, &lasts)) != NULL) { flags = strtok_r(NULL, ":", &lasts); flags = (flags != NULL) ? flags : ""; } free(keyword); struct stat statbuf; off_t size = 0; long age = 0; if (stat(action, &statbuf) == 0) { size = statbuf.st_size; age = statbuf.st_mtime; } snprintf(buffer, sizeof (buffer), "%s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%ld, %s=%lu", KEY_NAME, GetCustMsg(SE_SYSTEM_LOG_DESC), KEY_TYPE, GetCustMsg(SE_TYPE_LOG), KEY_STATE, STATE_ON, KEY_PATH, action, KEY_FLAGS, flags, KEY_SIZE, size, KEY_MODTIME, age); lst_append(*lst_log, strdup(buffer)); buffer[0] = '\0'; } free(log_keyword); fclose(fp); Trace(TR_MISC, "SAM system log info obtained"); return (0); }
/* * get device log information * Device-logging messages are written to individual log files * There is one log file for each library, tape drive etc. Log files are * located in /var/opt/SUNWsamfs/devlog. The name of each log file is the * same as the equipment ordinal specified in the mcf file * flags (events) is one or more of: * all, date, err, default, detail, module, label etc. * * Returns a list of formatted strings * * name=name, * type=Log/Trace, * state=on/off, * path=filename, * flags=flags, * size=size, * modtime=last modified time (num of seconds since 1970) */ int get_devlog_info( sqm_lst_t **lst_devlog ) { drive_t *drive = NULL; library_t *lib = NULL; sqm_lst_t *lst_lib = NULL; node_t *node_lib = NULL, *node_drive = NULL; if (get_all_libraries(NULL, &lst_lib) != 0) { return (-1); } *lst_devlog = lst_create(); node_lib = lst_lib->head; while (node_lib != NULL) { int chars = 0; char buffer[BUFSIZ] = {0}; char *params = NULL; lib = (library_t *)node_lib->data; chars = snprintf(buffer, sizeof (buffer), "%s=%s %s %02d, %s=%s", KEY_NAME, GetCustMsg(SE_DEVICE_LOG_DESC), (strcmp(lib->base_info.equ_type, "hy") == 0) ? GetCustMsg(SE_HISTORIAN_DESC) : lib->base_info.set, lib->base_info.eq, KEY_TYPE, GetCustMsg(SE_TYPE_LOG)); if (devlog_params(lib->base_info.eq, ¶ms) != NULL) { ADD_DELIM(chars, buffer); strlcat(buffer, params, sizeof (buffer)); free(params); params = NULL; lst_append(*lst_devlog, strdup(buffer)); } /* now the devlog for drives */ node_drive = lib->drive_list->head; while (node_drive != NULL) { buffer[0] = '\0'; chars = 0; drive = (drive_t *)node_drive->data; chars = snprintf(buffer, sizeof (buffer), "%s=%s %s %02d, %s=%s", KEY_NAME, GetCustMsg(SE_DEVICE_LOG_DESC), drive->base_info.set, drive->base_info.eq, KEY_TYPE, GetCustMsg(SE_TYPE_LOG)); if (devlog_params(drive->base_info.eq, ¶ms) != NULL) { ADD_DELIM(chars, buffer); strlcat(buffer, params, sizeof (buffer)); free(params); params = NULL; lst_append(*lst_devlog, strdup(buffer)); } node_drive = node_drive->next; } buffer[0] = '\0'; chars = 0; node_lib = node_lib->next; } lst_free_deep_typed(lst_lib, FREEFUNCCAST(free_library)); return (0); }
/* * Read disk volumes. */ int parse_diskvols_conf( char *file, /* path at which to read the diskvols.conf */ diskvols_cfg_t **cfg) /* malloced return value */ { int errors; char *first_err; Trace(TR_OPRMSG, "parsing diskvols file %s", Str(file)); if (ISNULL(file, cfg)) { Trace(TR_OPRMSG, "parsing diskvols file failed: %s", samerrmsg); return (-1); } if (init_static_variables() != 0) { Trace(TR_OPRMSG, "parsing diskvols file failed: %s", samerrmsg); return (-1); } if (strcmp(DISKVOL_CFG, file) != 0) { file_required = B_TRUE; } dv_cfg = mallocer(sizeof (diskvols_cfg_t)); if (dv_cfg == NULL) { Trace(TR_OPRMSG, "parsing diskvols file failed: %s", samerrmsg); return (-1); } memset(dv_cfg, 0, sizeof (diskvols_cfg_t)); dv_cfg->disk_vol_list = lst_create(); if (dv_cfg->disk_vol_list == NULL) { free_diskvols_cfg(dv_cfg); *cfg = NULL; Trace(TR_OPRMSG, "parsing diskvols file failed: %s", samerrmsg); return (-1); } dv_cfg->client_list = lst_create(); if (dv_cfg->client_list == NULL) { free_diskvols_cfg(dv_cfg); *cfg = NULL; Trace(TR_OPRMSG, "parsing diskvols file failed: %s", samerrmsg); return (-1); } dv_cfg->read_time = time(0); *cfg = dv_cfg; errors = ReadCfg(file, dirProcTable, dir_name, token, read_cfg_msg); if (errors != 0 && !(errors == -1 && !file_required)) { /* The absence of a command file is not an error */ if (errors == -1) { if (no_cmd_file) { /* * The absence of a command file * is not an error */ Trace(TR_OPRMSG, "parsing diskvols, no file present"); return (0); } free_diskvols_cfg(*cfg); *cfg = NULL; /* other access errors are an error */ samerrno = SE_CFG_OPEN_FAILED; /* open failed for %s: %s */ snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(SE_CFG_OPEN_FAILED), file, open_error); Trace(TR_OPRMSG, "parsing diskvols file failed: %s", samerrmsg); return (-1); } else if (errors == 1 && empty_cmd_file) { Trace(TR_OPRMSG, "parsing diskvols, empty file"); return (0); } free_diskvols_cfg(*cfg); *cfg = NULL; if (error_list != NULL && error_list->head != NULL) { first_err = ((parsing_error_t *)error_list->head->data)->msg; } else { first_err = "NULL"; } /* %s contains %d error(s) first:%s */ samerrno = SE_CONFIG_ERROR; snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(SE_CONFIG_ERROR), file, errors, first_err); Trace(TR_OPRMSG, "parsing diskvols file failed: %s", samerrmsg); return (-1); } Trace(TR_OPRMSG, "parsed diskvols file"); return (0); }
/* * function to get information about a running processes that match the input * parameters. */ int get_process_jobs( ctx_t *ctx /* ARGSUSED */, char *filter, /* see Filter Strings in process_job.h */ sqm_lst_t **job_list) /* list of proc_job_t */ { static char *procdir = "/proc"; /* standard /proc directory */ struct dirent64 *dent; struct dirent64 *dentp; DIR *dirp; char pname[MAXPATHLEN+1]; Trace(TR_MISC, "getting process job with filter %s", Str(filter)); if (ISNULL(job_list)) { Trace(TR_OPRMSG, "getting process jobs failed %d %s", samerrno, samerrmsg); return (-1); } if ((dirp = opendir(procdir)) == NULL) { samerrno = SE_OPENDIR_FAILED; snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(samerrno), procdir, ""); strlcat(samerrmsg, strerror(errno), MAX_MSG_LEN); Trace(TR_OPRMSG, "open dir %s failed", procdir); return (-1); } dent = mallocer(sizeof (struct dirent64) + MAXPATHLEN + 1); if (dent == NULL) { closedir(dirp); return (-1); } *job_list = lst_create(); if (*job_list == NULL) { Trace(TR_ERR, "getting process jobs failed %d %s", samerrno, samerrmsg); (void) closedir(dirp); free(dent); return (-1); } /* for each active process --- */ while ((readdir64_r(dirp, dent, &dentp)) == 0) { int procfd; /* filedescriptor for /proc/nnnnn/psinfo */ psinfo_t info; /* process information from /proc */ char *job_str; if (dentp == NULL) { break; } if (dentp->d_name[0] == '.') /* skip . and .. */ continue; snprintf(pname, sizeof (pname), "%s/%s/psinfo", procdir, dentp->d_name); if ((procfd = open(pname, O_RDONLY)) == -1) { continue; } /* * Get the info structure for the process and close quickly. */ if (readbuf(procfd, (char *)&info, sizeof (info)) < 0) { continue; } (void) close(procfd); if (info.pr_lwp.pr_state == 0) /* can't happen? */ continue; /* Screen out processes that do not match our criteria. */ /* * make this a helper function that takes an info * and a proc_job and returns true if match has been made. * this implies a signature change for this function to take * a job. */ if (psinfo_matches_filter(info, filter)) { if (create_process_job(&info, &job_str) != 0) { (void) closedir(dirp); } lst_append(*job_list, job_str); } } (void) closedir(dirp); free(dent); return (0); }
/* * release_files * Used to release files and directories and to set releaser * attributes for files and directories. * * * Attr Flags * RL_OPT_RECURSIVE * RL_OPT_NEVER * RL_OPT_WHEN_1 * RL_OPT_PARTIAL * RL_OPT_DEFAULTS * * If any attrubute other than RL_OPT_RECURSIVE is specified the disk space * will not be released. Instead the indicated attributes will be set * for each file in the file list. * * The RL_OPT_NEVER & RL_OPT_ALWAYS_WHEN_1 are * mutually exclusive. * * PARAMS: * sqm_lst_t *files, IN - list of fully quallified file names * int32_t options IN - bit fields indicate release options (see above). * int32_t *partial_sz IN - * RETURNS: * success - 0 operation successfully issued release not necessarily * complete. * error - -1 */ int release_files(ctx_t *c /* ARGSUSED */, sqm_lst_t *files, int32_t options, int32_t partial_sz, char **job_id) { char buf[32]; char **command; node_t *n; argbuf_t *arg; size_t len = MAXPATHLEN * 2; boolean_t found_one = B_FALSE; pid_t pid; int ret; int status; FILE *out; FILE *err; exec_cleanup_info_t *cl; char release_s_buf[32]; int arg_cnt; int cur_arg = 0; if (ISNULL(files, job_id)) { Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } /* * Determine how many args to the command and create the command * array. Note that command is malloced because the number of files * is not known prior to execution. The arguments themselves need * not be malloced because the child process will get a copy. * Include space in the command array for: * - the command * - all possible options * - an entry for each file in the list. * - entry for the NULL */ arg_cnt = 1 + 6 + files->length + 1; command = (char **)calloc(arg_cnt, sizeof (char *)); if (command == NULL) { setsamerr(SE_NO_MEM); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } command[cur_arg++] = RELEASE_FILES_CMD; *buf = '\0'; if (partial_sz) { snprintf(release_s_buf, sizeof (release_s_buf), "-s%d ", partial_sz); command[cur_arg++] = release_s_buf; } if (options & RL_OPT_NEVER) { command[cur_arg++] = "-n"; } if (options & RL_OPT_WHEN_1) { command[cur_arg++] = "-a"; } if (options & RL_OPT_PARTIAL) { command[cur_arg++] = "-p"; } if (options & RL_OPT_DEFAULTS) { command[cur_arg++] = "-d"; } /* Recursive must be specified last */ if (options & RL_OPT_RECURSIVE) { command[cur_arg++] = "-r"; } /* make the argument buffer for the activity */ arg = (argbuf_t *)mallocer(sizeof (releasebuf_t)); if (arg == NULL) { free(command); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } arg->rl.filepaths = lst_create(); if (arg->rl.filepaths == NULL) { free(command); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } arg->rl.options = options; arg->rl.partial_sz = partial_sz; /* add the file names to the cmd string and the argument buffer */ for (n = files->head; n != NULL; n = n->next) { if (n->data != NULL) { char *cur_file; command[cur_arg++] = (char *)n->data; found_one = B_TRUE; cur_file = copystr(n->data); if (cur_file == NULL) { free(command); free_argbuf(SAMA_RELEASEFILES, arg); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } if (lst_append(arg->rl.filepaths, cur_file) != 0) { free(command); free(cur_file); free_argbuf(SAMA_RELEASEFILES, arg); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } } } /* * Check that at least one file was found. */ if (!found_one) { free(command); free_argbuf(SAMA_RELEASEFILES, arg); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } /* create the activity */ ret = start_activity(display_release_activity, kill_fork, SAMA_RELEASEFILES, arg, job_id); if (ret != 0) { free(command); free_argbuf(SAMA_RELEASEFILES, arg); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } /* * create the cleanup struct prior to the exec because it is * easier to cleanup here if the malloc fails. */ cl = (exec_cleanup_info_t *)mallocer(sizeof (exec_cleanup_info_t)); if (cl == NULL) { free(command); lst_free_deep(arg->rl.filepaths); end_this_activity(*job_id); Trace(TR_ERR, "release files failed, error:%d %s", samerrno, samerrmsg); return (-1); } /* exec the process */ pid = exec_mgmt_cmd(&out, &err, command); if (pid < 0) { free(command); lst_free_deep(arg->rl.filepaths); end_this_activity(*job_id); Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } free(command); set_pid_or_tid(*job_id, pid, 0); /* setup struct for call to cleanup */ strlcpy(cl->func, RELEASE_FILES_CMD, sizeof (cl->func)); cl->pid = pid; strlcpy(cl->job_id, *job_id, MAXNAMELEN); cl->streams[0] = out; cl->streams[1] = err; /* possibly return the results or async notification */ ret = bounded_activity_wait(&status, 10, *job_id, pid, cl, cleanup_after_exec_get_output); if (ret == -1) { samerrno = SE_RELEASE_FILES_FAILED; snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(SE_RELEASE_FILES_FAILED)); free(*job_id); *job_id = NULL; Trace(TR_ERR, "release files failed:%s", samerrmsg); return (-1); } else if (ret == 0) { /* * job_id was set by start_activity. Clear it now * so that the caller knows the request has been submitted. */ free(*job_id); *job_id = NULL; Trace(TR_MISC, "release files completed"); } Trace(TR_MISC, "leaving release files"); return (0); }
int list_dir( ctx_t *c, int maxentries, char *filepath, char *restrictions, sqm_lst_t **direntries) /* ARGSUSED */ { int rval = 0; DIR *curdir; /* Variable for directory system calls */ struct dirent64 *entry; /* Pointer to a directory entry */ struct dirent64 *entryp; struct stat64 sout; restrict_t filter = {0}; char *data; /* Pointer to data item to add to list */ char fullpath[MAXPATHLEN]; /* Set up wildcard restrictions */ rval = set_restrict(restrictions, &filter); if (rval) { return (rval); } curdir = opendir(filepath); /* Set up to ask for directory entries */ if (curdir == NULL) { return (samrerr(SE_NOSUCHPATH, filepath)); } *direntries = lst_create(); /* Return results in this list */ if (*direntries == NULL) { closedir(curdir); return (-1); /* If allocation failed, samerr is set */ } entry = mallocer(sizeof (struct dirent64) + MAXPATHLEN + 1); if (entry == NULL) { closedir(curdir); lst_free(*direntries); *direntries = NULL; return (-1); } /* Walk through directory entries */ while ((rval = readdir64_r(curdir, entry, &entryp)) == 0) { if (entryp == NULL) { break; } if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) { continue; } /* Create full pathname and get stat info */ snprintf( fullpath, MAXPATHLEN, "%s/%s", filepath, entry->d_name); if (stat64(fullpath, &sout) != 0) { continue; /* Ignore file which can't be stat'ed */ } if (check_restrict_stat(entry->d_name, &sout, &filter)) continue; /* Not this entry */ data = copystr(entry->d_name); /* Copy data to allocated mem */ if (data == NULL) { rval = -1; break; /* samerr already set */ } lst_append(*direntries, data); if ((*direntries)->length >= maxentries) break; /* Keep list to designated limits */ } free(entry); if (rval) { lst_free_deep(*direntries); /* On failure, don't return list */ *direntries = NULL; } else { lst_qsort(*direntries, node_cmp); } closedir(curdir); return (rval); }
/* * functions to get a fs list which is doing release job. * the list is a list of structure release_fs_t; */ int get_releasing_fs_list( ctx_t *ctx, /* ARGSUSED */ sqm_lst_t **releasing_fs_list) /* a list of release_fs_t, */ /* must be freed by caller */ { int numfs; /* Number of filesystems */ struct sam_fs_info *finfo = NULL; struct sam_fs_status *fsarray; release_fs_t *rel_fs; int i; Trace(TR_MISC, "getting releasing file system"); if ((numfs = GetFsStatus(&fsarray)) == -1) { samerrno = SE_GET_FS_STATUS_FAILED; snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(samerrno)); Trace(TR_ERR, "%s", samerrmsg); /* * returns -2. */ *releasing_fs_list = lst_create(); if (*releasing_fs_list == NULL) { Trace(TR_ERR, "%s", samerrmsg); return (-1); } return (-2); } if (finfo != NULL) { free(finfo); } finfo = (struct sam_fs_info *) mallocer(numfs * sizeof (struct sam_fs_info)); if (finfo == NULL) { Trace(TR_ERR, "%s", samerrmsg); goto error; } for (i = 0; i < numfs; i++) { struct sam_fs_status *fs; struct sam_fs_info *fi; fs = fsarray + i; fi = finfo + i; if (GetFsInfo(fs->fs_name, fi) == -1) { samerrno = SE_GET_FS_INFO_FAILED; snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(samerrno), fs->fs_name); Trace(TR_ERR, "%s", samerrmsg); goto error; } if (!(fi->fi_status & FS_MOUNTED)) { continue; } } free(fsarray); *releasing_fs_list = lst_create(); if (*releasing_fs_list == NULL) { Trace(TR_ERR, "%s", samerrmsg); goto error; } for (i = 0; i < numfs; i++) { struct sam_fs_info *fi; int pct; /* Disk free space percentage */ fi = finfo + i; if (!(fi->fi_status & FS_MOUNTED)) { continue; } if (fi->fi_status & FS_RELEASING) { rel_fs = (release_fs_t *) mallocer(numfs * sizeof (release_fs_t)); if (rel_fs == NULL) { Trace(TR_ERR, "%s", samerrmsg); lst_free_deep(*releasing_fs_list); *releasing_fs_list = NULL; return (-1); } strlcpy(rel_fs->fi_name, fi->fi_name, sizeof (rel_fs->fi_name)); pct = llpercent_used(fi->fi_capacity, fi->fi_space); rel_fs->used_pct = 100 - pct; rel_fs->fi_low = fi->fi_low; if (lst_append(*releasing_fs_list, rel_fs) == -1) { free(rel_fs); lst_free_deep(*releasing_fs_list); Trace(TR_ERR, "%s", samerrmsg); *releasing_fs_list = NULL; return (-1); } } } if (finfo) { free(finfo); } Trace(TR_MISC, "finished getting releasing file system"); return (0); error: if (fsarray) { free(fsarray); } if (finfo) { free(finfo); } return (-1); }
void processExpression (token inputToken, FILE *in, int debugMode) { /**********************************************/ /* Declare both stack head pointers here */ LIST *opList = lst_create(); LIST *valList = lst_create(); /* Loop until the expression reaches its End */ while (inputToken.type != EOLN) { /* The expression contains an OPERATOR */ if (inputToken.type == OPERATOR) { //DEBUGGING if(debugMode) { printf ("OP:%c, " ,inputToken.op); } //DEBUGGING if(inputToken.op == '(') { push(opList, inputToken.op); } if(inputToken.op == '+' || inputToken.op == '-') { while(!lst_is_empty(opList) && top(opList) == '+' || top(opList) == '-' || top(opList) == '*' || top(opList) == '/') { pop_eval(opList, valList); } push(opList, inputToken.op); } if(inputToken.op == '*' || inputToken.op == '/') { while(!lst_is_empty(opList) && top(opList) == '+' || top(opList) == '-' || top(opList) == '*' || top(opList) == '/') { pop_eval(opList, valList); } push(opList, inputToken.op); } if(inputToken.op == ')') { while(!lst_is_empty(opList) && top(opList) != '(') { pop_eval(opList, valList); } if(lst_is_empty(opList)) { printf("\nERROR. OP Stack EMPTY!\n"); } else { pop(opList); } } } else if (inputToken.type == VALUE) { //DEBUGGING if(debugMode) { printf ("Val: %d, ", inputToken.val); } //DEBUGGING push(valList, inputToken.val); } /* get next token from input */ inputToken = getInputToken (in); } /* The expression has reached its end */ // add code to perform this operation here while(!lst_is_empty(opList)) { pop_eval(opList, valList); } printf("\nRESULT: %d", top(valList)); pop(valList); if(!lst_is_empty(valList)) { printf("\nERROR: ValueStack is not EMPTY %d\n", top(valList)); } printf ("\n"); }
/* * filepath may be either a directory or a fully-qualified path. * if it's fully-qualified, only directory entries that sort alphabetically * after the specified file will be returned. * * morefiles will be set if there are more entries left in the directory * after maxentries have been returned. This is intended to let the caller * know they can continue reading. * * Note that the directory may change while we're reading it. If it does, * files that have been added or removed since we started reading it may * not be accurately reflected. */ int list_directory( ctx_t *c, /* ARGSUSED */ int maxentries, char *listDir, /* directory to list */ char *startFile, /* if continuing, start here */ char *restrictions, uint32_t *morefiles, /* OUT */ sqm_lst_t **direntries) /* OUT */ { int rval = 0; int st = 0; DIR *curdir; /* Variable for directory system calls */ dirent64_t *entry; /* Pointer to a directory entry */ dirent64_t *entryp; struct stat64 sout; restrict_t filter = {0}; char *data; /* Pointer to data item to add to list */ node_t *node; sqm_lst_t *lstp = NULL; char buf[MAXPATHLEN + 1]; char *fname; if (ISNULL(listDir, direntries, morefiles)) { return (-1); } *morefiles = 0; /* Set up wildcard restrictions */ rval = set_restrict(restrictions, &filter); if (rval) { return (rval); } curdir = opendir(listDir); /* Set up to ask for directory entries */ if (curdir == NULL) { return (samrerr(SE_NOSUCHPATH, listDir)); } *direntries = lst_create(); /* Return results in this list */ if (*direntries == NULL) { closedir(curdir); return (-1); /* If allocation failed, samerr is set */ } lstp = *direntries; entry = mallocer(sizeof (struct dirent64) + MAXPATHLEN + 1); if (entry == NULL) { closedir(curdir); lst_free(*direntries); *direntries = NULL; return (-1); } /* Walk through directory entries */ while ((rval = readdir64_r(curdir, entry, &entryp)) == 0) { if (entryp == NULL) { break; } fname = (char *)&(entry->d_name[0]); if ((strcmp(fname, ".") == 0) || (strcmp(fname, "..") == 0)) { continue; } /* * If we were given a non-directory, start after * that file alphabetically. */ if (startFile != NULL) { if ((strcmp(fname, startFile)) <= 0) { continue; } } /* Create full pathname and get stat info */ snprintf(buf, sizeof (buf), "%s/%s", listDir, fname); if (lstat64(buf, &sout) != 0) { continue; /* Ignore file which can't be stat'ed */ } /* * think about ways to avoid a double-stat in when we're * fetching file details */ if (check_restrict_stat(fname, &sout, &filter)) { continue; /* Not this entry */ } /* copy to allocated struct */ data = copystr(fname); if (data == NULL) { rval = -1; break; /* samerr already set */ } /* * caller wants all entries for the directory * should there be a top-end limit, to avoid the case where * the directory has millions of entries? */ if (maxentries <= 0) { rval = lst_append(lstp, data); if (rval != 0) { free(data); break; } continue; } /* * Directory may have more entries than requested, so pre-sort * the list so we return the first <n> sorted alphabetically. */ for (node = lstp->head; node != NULL; node = node->next) { st = strcmp(data, (char *)(node->data)); if (st > 0) { continue; } if (st < 0) { rval = lst_ins_before(lstp, node, data); data = NULL; } if ((rval != 0) || (st == 0)) { free(data); data = NULL; } break; } /* entry sorts higher than existing entries */ if (data != NULL) { if (lstp->length < maxentries) { rval = lst_append(lstp, data); if (rval != 0) { free(data); break; } } else { /* no room for this entry */ free(data); (*morefiles)++; } } /* Keep list to designated limits */ if (lstp->length > maxentries) { /* pop off the last entry */ lst_remove(lstp, lstp->tail); (*morefiles)++; } } closedir(curdir); free(entry); if (rval) { lst_free_deep(*direntries); *direntries = NULL; } else if (maxentries <= 0) { lst_qsort(*direntries, node_cmp); } return (rval); }
/* Restore child nodes. Recursive. */ static int restore_children(char *dir_name, int *copy, char *dest, char *mountpt, dumpspec_t *dsp, replace_t replace, boolean_t count_only) { int st; char childdest[MAXPATHLEN + 1]; char msgbuf[MAX_MSGBUF_SIZE] = {0}; char catmsg[MAX_MSGBUF_SIZE] = {0}; sqm_lst_t *lstp = NULL; sqm_lst_t *dirlist = NULL; uint32_t morefiles = 0; restrict_t filter; filedetails_t *details; char *ptr; char startFrom[MAXPATHLEN + 1]; node_t *node; char *lastFile = NULL; char *startp; char *destp; dirlist = lst_create(); if (dirlist == NULL) { return (-1); } memset(&filter, 0, sizeof (restrict_t)); /* TODO: Add testcancel points and cleanup function */ startFrom[0] = '\0'; /* * get file info from the database in chunks so as not to * overwhelm ourselves if we're restoring a huge directory */ do { lstp = lst_create(); if (lstp == NULL) { goto done; } st = list_snapshot_files(dsp->fsname, dsp->snapname, dir_name, startFrom, filter, 0, 2048, FALSE, &morefiles, lstp); if (st != 0) { /* list_snapshot_files doesn't set samerrmsg */ snprintf(msgbuf, sizeof (msgbuf), GetCustMsg(SE_RESTORE_FAILED), ""); snprintf(catmsg, sizeof (catmsg), "%d %s ", st, strerror(st)); strlcat(msgbuf, catmsg, sizeof (msgbuf)); strlcat(msgbuf, dir_name, sizeof (msgbuf)); rlog(dsp->logfil, msgbuf, NULL, NULL); PostEvent(DUMP_CLASS, DUMP_INTERRUPTED_SUBCLASS, SE_RESTORE_FAILED, LOG_ERR, msgbuf, NOTIFY_AS_FAULT); goto done; } /* * Create new destination path - add filename with * strlcat to avoid possible problems with % in * the pathname. */ strlcpy(childdest, dest, MAXPATHLEN + 1); strlcat(childdest, "/", MAXPATHLEN + 1); destp = childdest + strlen(childdest); for (node = lstp->head; node != NULL; node = node->next) { details = node->data; if (details == NULL) { continue; } /* * save the path name in case we need it to get * more files */ lastFile = details->file_name; *destp = '\0'; strlcat(childdest, details->file_name, MAXPATHLEN + 1); /* if we're only counting, don't call restore_node */ /* Restore the child node */ if (!count_only) { st = restore_node(details, copy, childdest, mountpt, dsp, replace); if (st != 0) { strlcpy(catmsg, GetCustMsg(SE_RESTORE_FAILED), sizeof (catmsg)); snprintf(msgbuf, sizeof (msgbuf), catmsg, samerrmsg); rlog(dsp->logfil, msgbuf, NULL, NULL); PostEvent(DUMP_CLASS, DUMP_INTERRUPTED_SUBCLASS, SE_RESTORE_FAILED, LOG_ERR, msgbuf, NOTIFY_AS_FAULT); /* file already exists isn't fatal */ if (samerrno == SE_FILE_ALREADY_EXISTS) { st = 0; } } } if (S_ISDIR(details->prot)) { lst_append(dirlist, details->file_name); /* ensure not doubly deleted */ details->file_name = NULL; } } if (count_only) { restore_max += lstp->length; } if (lastFile) { strlcpy(startFrom, lastFile, sizeof (startFrom)); } lst_free_deep_typed(lstp, FREEFUNCCAST(free_file_details)); lstp = NULL; } while (morefiles > 0); /* restore any directories we found along the way */ strlcpy(startFrom, dir_name, sizeof (startFrom)); strlcat(startFrom, "/", sizeof (startFrom)); startp = startFrom + strlen(startFrom); for (node = dirlist->head; node != NULL; node = node->next) { ptr = (char *)node->data; *startp = '\0'; /* Create new source path */ strlcat(startp, ptr, sizeof (startFrom)); /* Create new destination path */ snprintf(childdest, MAXPATHLEN + 1, "%s/%s", dest, ptr); /* this will log individual errors for failure */ (void) restore_children(startFrom, copy, childdest, mountpt, dsp, replace, count_only); } done: if (lstp != NULL) { lst_free_deep_typed(lstp, FREEFUNCCAST(free_file_details)); } if (dirlist != NULL) { lst_free_deep(dirlist); } return (st); }
/* * Function to get information about all pending load information. */ int get_pending_load_info( ctx_t *ctx, /* ARGSUSED */ sqm_lst_t **pending_load_infos) /* OUT - list of pending_load_info_t */ { shm_alloc_t preview_shm; shm_preview_tbl_t *shm_preview_tbl; preview_tbl_t *preview_tbl; preview_t *p; pending_load_info_t *info = NULL; sqm_lst_t *load_infos = NULL; struct passwd *pw = NULL; time_t now; int avail; /* available entry count */ int count; /* active entry count */ int i; Trace(TR_MISC, "getting pending load info"); if (ISNULL(pending_load_infos)) { Trace(TR_OPRMSG, "null argument found"); goto err; } load_infos = lst_create(); if (load_infos == NULL) { Trace(TR_OPRMSG, "out of memory"); goto err; } Trace(TR_OPRMSG, "attaching to shared memory"); preview_shm.shmid = shmget(SHM_PREVIEW_KEY, 0, 0); if (preview_shm.shmid < 0) { samerrno = SE_PREVIEW_SHM_NOT_FOUND; snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(samerrno)); Trace(TR_OPRMSG, "unable to find preview shared memory segment"); *pending_load_infos = load_infos; Trace(TR_MISC, "got 0 pending load info"); return (-2); } preview_shm.shared_memory = shmat(preview_shm.shmid, NULL, SHM_RDONLY); if (preview_shm.shared_memory == (void *)-1) { samerrno = SE_PREVIEW_SHM_ATTACH_FAILED; snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(samerrno)); Trace(TR_OPRMSG, "unable to attach preview shared memory segment"); goto err; } shm_preview_tbl = (shm_preview_tbl_t *)preview_shm.shared_memory; preview_tbl = &shm_preview_tbl->preview_table; Trace(TR_OPRMSG, "creating pending load info list"); avail = preview_tbl->avail; count = preview_tbl->ptbl_count; for (i = 0; i < avail && count != 0; i++) { p = &preview_tbl->p[i]; if (!p->in_use) continue; count--; info = (pending_load_info_t *) mallocer(sizeof (pending_load_info_t)); if (info == NULL) { Trace(TR_OPRMSG, "out of memory"); goto err; } info->id = i; info->flags = 0; if (p->busy) info->flags |= LD_BUSY; if (p->in_use) info->flags |= LD_IN_USE; if (p->p_error) info->flags |= LD_P_ERROR; if (p->write) info->flags |= LD_WRITE; if (p->fs_req) info->flags |= LD_FS_REQ; if (p->block_io) info->flags |= LD_BLOCK_IO; if (p->stage) info->flags |= LD_STAGE; if (p->flip_side) info->flags |= LD_FLIP_SIDE; info->count = p->count; info->robot_equ = p->robot_equ; info->remote_equ = p->remote_equ; snprintf(info->media, sizeof (info->media), sam_mediatoa(p->resource.archive.rm_info.media)); info->slot = p->slot; info->ptime = p->ptime; now = time(NULL); info->age = now - p->ptime; info->priority = p->priority; info->pid = p->handle.pid; pw = getpwuid(getuid()); if (pw != NULL) { snprintf(info->user, sizeof (info->user), pw->pw_name); } else { snprintf(info->user, sizeof (info->user), "Unknown user"); } snprintf(info->vsn, sizeof (vsn_t), p->resource.archive.vsn); if (lst_append(load_infos, info) == -1) { Trace(TR_OPRMSG, "lst append failed"); goto err; } } shmdt(preview_shm.shared_memory); *pending_load_infos = load_infos; Trace(TR_OPRMSG, "returned pending load info list of size [%d]", load_infos->length); Trace(TR_MISC, "got pending load info"); return (0); err: if (preview_shm.shared_memory != (void *)-1) { shmdt(preview_shm.shared_memory); } if (load_infos) free_list_of_pending_load_info(load_infos); if (info) free_pending_load_info(info); Trace(TR_ERR, "get pending load info failed: %s", samerrmsg); return (-1); }
int main() { printf("REMINDER: This test suite is NOT exhaustive. Passing all of these tests does NOT mean you will get 100%% on the project.\n"); srand(time(NULL)); int i; /********* 0 lst_is_empty **********/ LIST *empty = lst_create(); LIST *one = lst_create(); LIST *large = lst_create(); lst_push_back(one, 5); int rand_size = rand() % 20; for(i = 0; i < rand_size; i++) { lst_push_back(large, i); } printf("\n\nTest: 0A\nDescription: Testing lst_is_empty with List of length 0\nExpected output: 1\n"); printf("Your output: %d\n", lst_is_empty(empty)); printf("\n\nTest: 0B\nDescription: Testing lst_is_empty with List of length 1\nExpected output: 0\n"); printf("Your output: %d\n", lst_is_empty(one)); printf("\n\nTest: 0CnDescription: Testing lst_is_empty with List of length %d\nExpected output: %d\n", rand_size, ((rand_size == 0) ? 1 : 0)); printf("Your output: %d\n", lst_is_empty(large)); FREE(large); FREE(one); FREE(empty); /********* 1 lst_print_rev **********/ LIST *rev1 = lst_create(); LIST *rev2 = lst_create(); for(i = 0; i < 5; i++) { lst_push_back(rev2, i); } printf("\n\nTest: 1A\nDescription: Testing lst_print_rev with List of length 5\nExpected output: \n[4, 3, 2, 1, 0]\n"); printf("Your output\n"); lst_print_rev(rev2); printf("\n\nTest: 1B\nDescription: Testing lst_print_rev with List of length 0\nExpected output: \n[ ]\n"); printf("Your output\n"); lst_print_rev(rev1); FREE(rev1); FREE(rev2); /********** 3 lst_pop_back ***********/ large = lst_create(); one = lst_create(); empty = lst_create(); for(i = 0; i < 8; i++) { lst_push_back(large, i); } lst_push_back(one, 6); printf("\n\nTest: 3A\nDescription: Testing lst_pop_back with List of length 0\nExpected output: <some arbitrary number (NO SEG FAULT!)>\n"); printf("Your output: %d\n", lst_pop_back(empty)); printf("\n\nTest: 3B\nDescription: Testing lst_pop_back with List of length 1\nExpected output: 6\n"); printf("Your output: %d\n", lst_pop_back(one)); printf("\n\nTest: 3C\nDescription: Testing lst_pop_back with List of length 8\nExpected output: 7\n"); printf("Your output: %d\n", lst_pop_back(large)); FREE(large); FREE(one); FREE(empty); /********** 5 lst_is_sorted ***********/ empty = lst_create(); LIST *sorted = lst_create(); LIST *unsorted = lst_create(); for(i = 0; i < 10; i++) { lst_push_back(sorted, i); lst_push_back(unsorted, i); } lst_push_back(unsorted, 5); printf("\n\nTest: 5A\nDescription: Testing lst_is_sorted with List of length 0\nExpected output: 1\n"); printf("Your output: %d\n", lst_is_sorted(empty)); printf("\n\nTest: 5B\nDescription: Testing lst_is_sorted with List of length 11\nExpected output: 0\n"); printf("Your output: %d\n", lst_is_sorted(unsorted)); printf("\n\nTest: 5C\nDescription: Testing lst_is_sorted with List of length 10\nExpected output: 1\n"); printf("Your output: %d\n", lst_is_sorted(sorted)); FREE(empty); FREE(sorted); FREE(unsorted); /********** 7 lst_length ***********/ empty = lst_create(); rand_size = rand() % 100; LIST *small = lst_create(); large = lst_create(); for(i = 0; i < rand_size; i++) { lst_push_back(large, rand() % 1000); } lst_push_back(small, 3); printf("\n\nTest: 7A\nDescription: Testing lst_length with List of length 0\nExpected output: 0\n"); printf("Your output: %d\n", lst_length(empty)); printf("\n\nTest: 7B\nDescription: Testing lst_length with List of length 1\nExpected output: 1\n"); printf("Your output: %d\n", lst_length(small)); printf("\n\nTest: 7C\nDescription: Testing lst_length with List of length %d\nExpected output: %d\n", rand_size, rand_size); printf("Your output: %d\n", lst_length(large)); FREE(empty); FREE(small); FREE(large); /********** 9 lst_clone ***********/ empty = lst_create(); small = lst_create(); large = lst_create(); lst_push_back(small, 3); rand_size = rand() % 10; for(i = 0; i < rand_size; i++) { lst_push_back(large, rand() % 500); } printf("\n\nTest 9A\nDescription: Testing lst_clone with List of length 0\nExpected output:\n"); lst_print(empty); printf("Your output: \n"); LIST *empty_clone = lst_clone(empty); lst_print(empty_clone); printf("\n\nTest 9B\nDescription: Testing lst_clone with List of length 1\nExpected output:\n"); lst_print(small); printf("Your output: \n"); LIST *small_clone = lst_clone(small); lst_print(small_clone); printf("\n\nTest 9C\nDescription: Testing lst_clone with List of random size\nExpected output:\n"); lst_print(large); printf("Your output: \n"); LIST *large_clone = lst_clone(large); lst_print(large_clone); FREE(empty); FREE(small); FREE(large); /********** 11 lst_to_array ***********/ large = lst_create(); rand_size = rand() % 50; for(i = 0; i < rand_size; i++) { lst_push_back(large, rand() % 100); } printf("\n\nTest 11A\nDescription: Testing lst_to_array with List of length %d\nExpected output:\n", rand_size); lst_print(large); printf("Your output: \n"); int *arr = lst_to_array(large); print_arr(arr, lst_length(large)); FREE(large); /********** 13 lst_filter_leq ***********/ large = lst_create(); empty = lst_create(); small = lst_create(); lst_push_back(small, 7); for(i = 0; i < 10; i++) { lst_push_back(large, i); } printf("\n\nTest 13A\nDescription: Testing lst_filter_leq with List of length 0 and cutoff of 5\nExpected output for original List after call to lst_filter_leq:\n"); LIST *leq_empty = lst_filter_leq(empty, 5); printf("[ ]\n"); printf("Your output of original List:\n"); lst_print(empty); printf("Expected output for new list of leq elements:\n"); printf("[ ]\n"); printf("Your output of new list of leq elements:\n"); lst_print(leq_empty); printf("\n\nTest 13B\nDescription: Testing lst_filter_leq with List of length 1 and cutoff of 7\nExpected output for original List after call to lst_filter_leq:\n"); LIST *leq_small = lst_filter_leq(small, 5); printf("[ 7 ]\n"); printf("Your output of original List:\n"); lst_print(small); printf("Expected output for new list of leq elements:\n"); printf("[ ]\n"); printf("Your output of new list of leq elements:\n"); lst_print(leq_small); printf("\n\nTest 13C\nDescription: Testing lst_filter_leq with List of length 0 and cutoff of 5\nExpected output for original List after call to lst_filter_leq:\n"); LIST *leq_large = lst_filter_leq(large, 5); printf("[ 6 7 8 9 ]\n"); printf("Your output of original List:\n"); lst_print(large); printf("Expected output for new list of leq elements:\n"); printf("[ 0 1 2 3 4 5 ]\n"); printf("Your output of new list of leq elements:\n"); lst_print(leq_large); FREE(leq_empty); FREE(leq_small); FREE(leq_large); FREE(empty); FREE(small); FREE(large); }