// validators static bool valid_header(fix_group* const group, const header* const hdr) { return valid_string(group, SenderCompID, fix_string_from_c_string(hdr->SenderCompID)) && valid_string(group, TargetCompID, fix_string_from_c_string(hdr->TargetCompID)) && valid_long(group, MsgSeqNum, hdr->MsgSeqNum) && valid_timestamp(group, SendingTime, &hdr->SendingTime) && valid_char(group, PossDupFlag, hdr->PossDupFlag); }
static bool valid_new_order_single(fix_group* const group, const new_order_single* const order) { return valid_string(group, Account, fix_string_from_c_string(order->Account)) && valid_string(group, ClOrdID, fix_string_from_c_string(order->ClOrdID)) && valid_timestamp(group, TransactTime, &order->TransactTime) && valid_char(group, HandlInst, order->HandlInst) && valid_char(group, OrdType, order->OrdType) && valid_char(group, Side, order->Side) && valid_char(group, TimeInForce, order->TimeInForce) && valid_double(group, Price, order->Price); }
string ConfigKey::identifier() const { const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, _id); if (!info) throw Error(SR_ERR_NA); return valid_string(info->id); }
string ConfigKey::description() const { const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, _id); if (!info) throw Error(SR_ERR_NA); return valid_string(info->name); }
void test_VIDIOC_G_AUDIO() { int ret_get, errno_get; struct v4l2_audio audio; struct v4l2_audio audio2; memset(&audio, 0xff, sizeof(audio)); ret_get = ioctl(get_video_fd(), VIDIOC_G_AUDIO, &audio); errno_get = errno; dprintf("\t%s:%u: VIDIOC_G_AUDIO, ret_get=%i, errno_get=%i\n", __FILE__, __LINE__, ret_get, errno_get); if (ret_get == 0) { CU_ASSERT_EQUAL(ret_get, 0); //CU_ASSERT_EQUAL(audio.index, ?); CU_ASSERT(0 < strlen((char *)audio.name)); CU_ASSERT(valid_string((char *)audio.name, sizeof(audio.name))); CU_ASSERT(valid_audio_capability(audio.capability)); CU_ASSERT(valid_audio_mode(audio.mode)); CU_ASSERT_EQUAL(audio.reserved[0], 0); CU_ASSERT_EQUAL(audio.reserved[1], 0); /* Check if the unused bytes of the name string are * also filled with zeros. Also check if there is any * padding byte between any two fields then this * padding byte is also filled with zeros. */ memset(&audio2, 0, sizeof(audio2)); audio2.index = audio.index; strncpy((char *)audio2.name, (char *)audio.name, sizeof(audio2.name)); audio2.capability = audio.capability; audio2.mode = audio.mode; CU_ASSERT_EQUAL(memcmp(&audio, &audio2, sizeof(audio)), 0); dprintf("\taudio = {.index=%u, .name=\"%s\", " ".capability=0x%X, .mode=0x%X, " ".reserved[]={ 0x%X, 0x%X } }\n", audio.index, audio.name, audio.capability, audio.mode, audio.reserved[0], audio.reserved[1] ); } else { CU_ASSERT_EQUAL(ret_get, -1); CU_ASSERT_EQUAL(errno_get, EINVAL); /* check if the audio structure is untouched */ memset(&audio2, 0xff, sizeof(audio2)); CU_ASSERT_EQUAL(memcmp(&audio, &audio2, sizeof(audio)), 0); } }
/* * syscall_stat * * Implementation of the stat system call, which obtains information about a * particular file or directory. You should use this as a guideline for how to * implement the other system calls in assignment 3. */ int syscall_stat(const char *path, struct stat *buf) { /* * Ensure the supplied path name and buffer are valid pointers */ if (!valid_string(path)) return -EFAULT; if (!valid_pointer(buf, sizeof(struct stat))) return -EFAULT; /* * Get the directory_entry object for this path from the filesystem */ directory_entry *entry; int r; char abs[PATH_MAX]; relative_to_absolute(abs, current_process->cwd, path, PATH_MAX); if (0 != (r = get_directory_entry(filesystem, abs, &entry))) return r; /* * Set all fields of the stat buffer */ buf->st_mode = entry->mode; buf->st_uid = 0; buf->st_gid = 0; buf->st_size = entry->size; buf->st_mtime = entry->mtime; return 0; }
char *family_name(uint16_t family_id) { if (families == NULL) return "no families loaded"; if (((family_id - 1) > hdr.num_families) || (family_id < 0)) return "family ID is invalid"; return valid_string(families[family_id].name, g_tmp); }
void test_VIDIOC_G_AUDOUT() { int ret_get, errno_get; struct v4l2_audioout audioout; struct v4l2_audioout audioout2; memset(&audioout, 0xff, sizeof(audioout)); ret_get = ioctl(get_video_fd(), VIDIOC_G_AUDOUT, &audioout); errno_get = errno; dprintf("\tVIDIOC_AUDIOOUT, ret_get=%i, errno_get=%i\n", ret_get, errno_get); if (ret_get == 0) { CU_ASSERT_EQUAL(ret_get, 0); //CU_ASSERT_EQUAL(audioout.index, ?); CU_ASSERT(0 < strlen( (char*)audioout.name )); CU_ASSERT(valid_string((char*)audioout.name, sizeof(audioout.name))); CU_ASSERT_EQUAL(audioout.capability, 0); CU_ASSERT_EQUAL(audioout.mode, 0); CU_ASSERT_EQUAL(audioout.reserved[0], 0); CU_ASSERT_EQUAL(audioout.reserved[1], 0); /* Check if the unused bytes of the name string is also filled * with zeros. Also check if there is any padding byte between * any two fields then this padding byte is also filled with zeros. */ memset(&audioout2, 0, sizeof(audioout2)); audioout2.index = audioout.index; strncpy((char*)audioout2.name, (char*)audioout.name, sizeof(audioout2.name)); audioout2.capability = audioout.capability; audioout2.mode = audioout.mode; CU_ASSERT_EQUAL(memcmp(&audioout, &audioout2, sizeof(audioout)), 0); dprintf("\taudioout = {.index=%u, .name=\"%s\", " ".capability=0x%X, .mode=0x%X, " ".reserved[]={ 0x%X, 0x%X } }\n", audioout.index, audioout.name, audioout.capability, audioout.mode, audioout.reserved[0], audioout.reserved[1] ); } else { CU_ASSERT_EQUAL(ret_get, -1); CU_ASSERT_EQUAL(errno_get, EINVAL); /* check if the audioout structure is untouched */ memset(&audioout2, 0xff, sizeof(audioout2)); CU_ASSERT_EQUAL(memcmp(&audioout, &audioout2, sizeof(audioout)), 0); } }
bool Student::SetSurname(const string surname) { string temp = GetSurname(); this->surname = surname; if (valid_string(this->surname)) { return 1; } else { this->surname = temp; return 0; } }
char *script_name(uint16_t script_id) { if (scripts == NULL) return "no scripts loaded"; if (((script_id - 1) > hdr.num_scripts) || (script_id < 0)) return "script ID is invalid"; if (script_id == 0) return "NO_SCRIPT"; return valid_string(scripts[script_id - 1].name, g_tmp); }
void print_script(FILE * f, script_ent_t * script) { int i; /* uint8_t *ptr; */ fprintf(f, "name = \"%s\"\n", valid_string(script->name, g_tmp)); if (strlen(script->org_name) > 0) fprintf(f, "org_name = \"%s\"\n", valid_string(script->org_name, g_tmp)); fprintf(f, "id = %d\n", script->script_num); fprintf(f, "version = %d\n", script->version); fprintf(f, "unused1 = %d\n", script->unused1); /* fprintf(f, "script_length = %d\n", script->script_length); */ fprintf(f, "script = {"); /* ptr = (uint8_t*)script->script; */ for (i = 0; i < (script->script_length << 1); i++) { if ((i & 7) == 0) fprintf(f, "\n"); fprintf(f, " 0x%02x,", script->script[i]); } fprintf(f, "\n}\n"); fprintf(f, "comment = \"%s\"\n", valid_string(script->comment, g_tmp)); }
int myAtoi_A(char* str) { int neg; int sign; int adder; int sz; int ret = 0; int i; char* copy_str; sz = strlen(str); copy_str = (char*)malloc(sizeof(char) * sz); memset(copy_str, 0, sizeof(char) * sz); preprocess_str(str, copy_str); sign = valid_string(copy_str); if(sign == -1) { return 0; } if(copy_str[0] == '-') { neg = 1; } sz = strlen(copy_str); for (i = sign; i < sz; i++) { if((ret * 10) < ret) { return (neg == 1) ? INT_MIN : INT_MAX; } adder = copy_str[i] - '0'; ret = ret * 10 + adder; if(ret < 0) { if(adder >= 8 && neg == 1) { return INT_MIN; } else if(adder == 7 && neg == 0) { return INT_MAX; } else { return (neg == 1) ? INT_MIN : INT_MAX; } } } return (neg == 1)? (0 - ret) : ret; }
int syscall_chdir(const char *path) { if (!valid_string(path)) return -EFAULT; char newcwd[PATH_MAX]; relative_to_absolute(newcwd, current_process->cwd, path, PATH_MAX); int r; directory_entry *entry; if (0 != (r = get_directory_entry(filesystem, newcwd, &entry))) return r; if (TYPE_DIR != entry->type) return -ENOTDIR; memmove(current_process->cwd, newcwd, PATH_MAX); return 0; }
static void do_check_menu(__u32 id, __u32 index, int ret_query, int errno_query, struct v4l2_querymenu *menu) { struct v4l2_querymenu menu2; if (ret_query == 0) { CU_ASSERT_EQUAL(ret_query, 0); dprintf("\tmenu = {.id=%u, .index=%i, .name=\"%s\", " ".reserved=0x%X }\n", menu->id, menu->index, menu->name, menu->reserved ); CU_ASSERT_EQUAL(menu->id, id); CU_ASSERT_EQUAL(menu->index, index); CU_ASSERT(0 < strlen((char*)menu->name)); CU_ASSERT(valid_string((char*)menu->name, sizeof(menu->name))); CU_ASSERT_EQUAL(menu->reserved, 0); /* Check if the unused bytes of the name string is also filled * with zeros. Also check if there is any padding byte between * any two fields then this padding byte is also filled with * zeros. */ memset(&menu2, 0, sizeof(menu2)); menu2.id = id; menu2.index = index; strncpy((char*)menu2.name, (char*)menu->name, sizeof(menu2.name)); CU_ASSERT_EQUAL(memcmp(menu, &menu2, sizeof(*menu)), 0); } else { CU_ASSERT_EQUAL(ret_query, -1); CU_ASSERT_EQUAL(errno_query, EINVAL); memset(&menu2, 0xff, sizeof(menu2)); menu2.id = id; menu2.index = index; CU_ASSERT(memcmp(&menu, &menu2, sizeof(menu))); } }
int syscall_open(const char *pathname, int flags) { if (!valid_string(pathname)) return -EFAULT; int fd = -1; for (fd = 0; fd < MAX_FDS; fd++) { if (NULL == current_process->filedesc[fd]) break; } if (MAX_FDS == fd) return -EMFILE; char abspath[PATH_MAX]; relative_to_absolute(abspath, current_process->cwd, pathname, PATH_MAX); directory_entry *entry; int r; if (0 != (r = get_directory_entry(filesystem, abspath, &entry))) return r; if ((flags == OPEN_DIRECTORY) && (entry->type != TYPE_DIR)) return -ENOTDIR; else if ((flags != OPEN_DIRECTORY) && (entry->type == TYPE_DIR)) return -EISDIR; filehandle *fh; if (TYPE_DIR == entry->type) fh = new_file(FH_DIR); else fh = new_file(FH_FILE); fh->entry = entry; fh->pos = 0; fh->entryno = 0; current_process->filedesc[fd] = fh; return fd; }
static int do_get_tuner(int f, __u32 index) { int ret_get, errno_get; struct v4l2_tuner tuner; struct v4l2_tuner tuner2; memset(&tuner, 0xff, sizeof(tuner)); tuner.index = index; ret_get = ioctl(f, VIDIOC_G_TUNER, &tuner); errno_get = errno; dprintf("\t%s:%u: VIDIOC_G_TUNER, ret_get=%i, errno_get=%i\n", __FILE__, __LINE__, ret_get, errno_get); if (ret_get == 0) { CU_ASSERT_EQUAL(ret_get, 0); CU_ASSERT_EQUAL(tuner.index, index); CU_ASSERT(0 < strlen( (char*)tuner.name )); CU_ASSERT(valid_string((char*)tuner.name, sizeof(tuner.name))); CU_ASSERT(valid_tuner_type(tuner.type)); CU_ASSERT(valid_tuner_capability(tuner.capability)); CU_ASSERT(tuner.rangelow <= tuner.rangehigh); CU_ASSERT(valid_tuner_sub(tuner.rxsubchans)); CU_ASSERT(valid_tuner_audmode(tuner.audmode)); /* tuner.signal can have any value */ //CU_ASSERT_EQUAL(tuner.signal, ???); /* tuner.afc can have any value */ //CU_ASSERT_EQUAL(tuner.afc, ???); CU_ASSERT_EQUAL(tuner.reserved[0], 0); CU_ASSERT_EQUAL(tuner.reserved[1], 0); CU_ASSERT_EQUAL(tuner.reserved[2], 0); CU_ASSERT_EQUAL(tuner.reserved[3], 0); /* Check if the unused bytes of the name string are also filled * with zeros. Also check if there is any padding byte between * any two fields then this padding byte is also filled with * zeros. */ memset(&tuner2, 0, sizeof(tuner2)); tuner2.index = tuner.index; strncpy((char*)tuner2.name, (char*)tuner.name, sizeof(tuner2.name)); tuner2.type = tuner.type; tuner2.capability = tuner.capability; tuner2.rangelow = tuner.rangelow; tuner2.rangehigh = tuner.rangehigh; tuner2.rxsubchans = tuner.rxsubchans; tuner2.audmode = tuner.audmode; tuner2.signal = tuner.signal; tuner2.afc = tuner.afc; CU_ASSERT_EQUAL(memcmp(&tuner, &tuner2, sizeof(tuner)), 0); dprintf("\ttuner = { " ".index = %u, " ".name = \"%s\", " ".type = %i, " ".capability = %u, " ".rangelow = %u, " ".rangehigh = %u, " ".rxsubchans = %u, " ".audmode = %u, " ".signal = %u, " ".afc = %i, " ".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X } }\n", tuner.index, tuner.name, tuner.type, tuner.capability, tuner.rangelow, tuner.rangehigh, tuner.rxsubchans, tuner.audmode, tuner.signal, tuner.afc, tuner.reserved[0], tuner.reserved[1], tuner.reserved[2], tuner.reserved[3] ); } else { dprintf("\t%s:%u: ret_get=%d (expected %d)\n", __FILE__, __LINE__, ret_get, -1); dprintf("\t%s:%u: errno_get=%d (expected %d)\n", __FILE__, __LINE__, errno_get, EINVAL); CU_ASSERT_EQUAL(ret_get, -1); CU_ASSERT_EQUAL(errno_get, EINVAL); } return ret_get; }
void test_VIDIOC_QUERYCTRL() { int ret_query, errno_query; struct v4l2_queryctrl queryctrl; struct v4l2_queryctrl queryctrl2; __u32 i; /* The available controls and their parameters * may change with different * - input or output * - tuner or modulator * - audio input or audio output * See V4L API specification rev. 0.24, Chapter 1.8. * "User Controls" for details * * TODO: iterate through the mentioned settings. * TODO: check for deprecated controls (maybe in a * separated test case which could fail when a * deprecated control is supported) */ for (i = V4L2_CID_BASE; i < V4L2_CID_LASTP1; i++) { memset(&queryctrl, 0xff, sizeof(queryctrl)); queryctrl.id = i; ret_query = ioctl(get_video_fd(), VIDIOC_QUERYCTRL, &queryctrl); errno_query = errno; dprintf("\t%s:%u: VIDIOC_QUERYCTRL, id=%u (V4L2_CID_BASE+%i), ret_query=%i, errno_query=%i\n", __FILE__, __LINE__, i, i-V4L2_CID_BASE, ret_query, errno_query); if (ret_query == 0) { CU_ASSERT_EQUAL(ret_query, 0); CU_ASSERT_EQUAL(queryctrl.id, i); CU_ASSERT(0 < strlen( (char*)queryctrl.name )); CU_ASSERT(valid_string((char*)queryctrl.name, sizeof(queryctrl.name))); CU_ASSERT(valid_control_type(queryctrl.type)); switch (queryctrl.type) { case V4L2_CTRL_TYPE_INTEGER: /* min < max, because otherwise this control makes no sense */ CU_ASSERT(queryctrl.minimum < queryctrl.maximum); CU_ASSERT(0 < queryctrl.step); CU_ASSERT(queryctrl.minimum <= queryctrl.default_value); CU_ASSERT(queryctrl.default_value <= queryctrl.maximum); break; case V4L2_CTRL_TYPE_BOOLEAN: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 1); CU_ASSERT_EQUAL(queryctrl.step, 1); CU_ASSERT((queryctrl.default_value == 0) || (queryctrl.default_value == 1)); break; case V4L2_CTRL_TYPE_MENU: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT(queryctrl.minimum <= queryctrl.default_value); CU_ASSERT_EQUAL(queryctrl.step, 1); CU_ASSERT(queryctrl.minimum <= queryctrl.default_value); CU_ASSERT(queryctrl.default_value <= queryctrl.maximum); break; case V4L2_CTRL_TYPE_BUTTON: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 0); CU_ASSERT_EQUAL(queryctrl.step, 0); CU_ASSERT_EQUAL(queryctrl.default_value, 0); break; case V4L2_CTRL_TYPE_INTEGER64: /* fallthrough */ case V4L2_CTRL_TYPE_CTRL_CLASS: /* These parameters are defined as n/a by V4L2, so * they should be filled with zeros, the same like * the reserved fields. */ CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 0); CU_ASSERT_EQUAL(queryctrl.step, 0); CU_ASSERT_EQUAL(queryctrl.default_value, 0); break; default: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 0); CU_ASSERT_EQUAL(queryctrl.step, 0); CU_ASSERT_EQUAL(queryctrl.default_value, 0); } CU_ASSERT(valid_control_flag(queryctrl.flags)); CU_ASSERT_EQUAL(queryctrl.reserved[0], 0); CU_ASSERT_EQUAL(queryctrl.reserved[1], 0); /* Check if the unused bytes of the name string are * also filled with zeros. Also check if there is any * padding byte between any two fields then this * padding byte is also filled with zeros. */ memset(&queryctrl2, 0, sizeof(queryctrl2)); queryctrl2.id = queryctrl.id; queryctrl2.type = queryctrl.type; strncpy((char*)queryctrl2.name, (char*)queryctrl.name, sizeof(queryctrl2.name)); queryctrl2.minimum = queryctrl.minimum; queryctrl2.maximum = queryctrl.maximum; queryctrl2.step = queryctrl.step; queryctrl2.default_value = queryctrl.default_value; queryctrl2.flags = queryctrl.flags; CU_ASSERT_EQUAL(memcmp(&queryctrl, &queryctrl2, sizeof(queryctrl)), 0); dprintf("\tqueryctrl = {.id=%u, .type=%i, .name=\"%s\", " ".minimum=%i, .maximum=%i, .step=%i, " ".default_value=%i, " ".flags=0x%X, " ".reserved[]={ 0x%X, 0x%X } }\n", queryctrl.id, queryctrl.type, queryctrl.name, queryctrl.minimum, queryctrl.maximum, queryctrl.step, queryctrl.default_value, queryctrl.flags, queryctrl.reserved[0], queryctrl.reserved[1] ); } else { CU_ASSERT_EQUAL(ret_query, -1); CU_ASSERT_EQUAL(errno_query, EINVAL); memset(&queryctrl2, 0xff, sizeof(queryctrl2)); queryctrl2.id = i; CU_ASSERT_EQUAL(memcmp(&queryctrl, &queryctrl2, sizeof(queryctrl)), 0); } } }
void test_VIDIOC_ENUMOUTPUT() { int ret_enum, errno_enum; struct v4l2_output output; struct v4l2_output output2; __u32 i; i = 0; do { memset(&output, 0xff, sizeof(output)); output.index = i; ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMOUTPUT, &output); errno_enum = errno; dprintf("\t%s:%u: VIDIOC_ENUMOUTPUT, ret_enum=%i, errno_enum=%i\n", __FILE__, __LINE__, ret_enum, errno_enum); if (ret_enum == 0) { CU_ASSERT_EQUAL(ret_enum, 0); CU_ASSERT_EQUAL(output.index, i); CU_ASSERT(0 < strlen( (char*)output.name )); CU_ASSERT(valid_string((char*)output.name, sizeof(output.name))); //CU_ASSERT_EQUAL(output.type, ?); //CU_ASSERT_EQUAL(output.audioset, ?); //CU_ASSERT_EQUAL(output.modulator, ?); CU_ASSERT(valid_v4l2_std_id(output.std)); CU_ASSERT_EQUAL(output.reserved[0], 0); CU_ASSERT_EQUAL(output.reserved[1], 0); CU_ASSERT_EQUAL(output.reserved[2], 0); CU_ASSERT_EQUAL(output.reserved[3], 0); /* Check if the unused bytes of the name string are * also filled with zeros. Also check if there is any * padding byte between any two fields then this * padding byte is also filled with zeros. */ memset(&output2, 0, sizeof(output2)); output2.index = output.index; strncpy((char*)output2.name, (char*)output.name, sizeof(output2.name)); output2.type = output.type; output2.audioset = output.audioset; output2.modulator = output.modulator; output2.std = output.std; CU_ASSERT_EQUAL(memcmp(&output, &output2, sizeof(output)), 0); dprintf("\toutput = {.index=%u, .name=\"%s\", " ".type=0x%X, .audioset=0x%X, .modulator=0x%X, " ".std=%llX, " ".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X } }\n", output.index, output.name, output.type, output.audioset, output.modulator, output.std, output.reserved[0], output.reserved[1], output.reserved[2], output.reserved[3] ); } else { CU_ASSERT_EQUAL(ret_enum, -1); CU_ASSERT_EQUAL(errno_enum, EINVAL); memset(&output2, 0xff, sizeof(output2)); output2.index = i; CU_ASSERT_EQUAL(memcmp(&output, &output2, sizeof(output)), 0); dprintf("\terrno=%i\n", errno); } i++; } while (ret_enum == 0); }
int dump_device_file(char *dumpdir) { char fname[255], fbase[255], *p; FILE *f, *fcfg; int i; /* create diretory */ strcpy(fname, "mkdir "); strcat(fname, dumpdir); system(fname); /* write the config file */ strcpy(fname, dumpdir); strcat(fname, "/config.cfg"); if ((fcfg = fopen(fname, "w+")) == NULL) return -1; fprintf(fcfg, "# this configiration file was generated automatically\n"); fprintf(fcfg, "# please modify it according to the rules :-)\n#\n"); fprintf(fcfg, "# the source file contained:\n"); fprintf(fcfg, "# %d families,\n", hdr.num_families); fprintf(fcfg, "# %d devices and\n", hdr.num_devices); fprintf(fcfg, "# %d scripts.\n\n\n", hdr.num_scripts); fprintf(fcfg, "# for the device file header\n"); fprintf(fcfg, "ver_major = %d\n", hdr.version[0]); fprintf(fcfg, "ver_minor = %d\n", hdr.version[1]); fprintf(fcfg, "ver_dot = %d\n", hdr.version[2]); fprintf(fcfg, "compat = %d\n", hdr.compat); fprintf(fcfg, "unused1a = %d\n", hdr.unused1a); fprintf(fcfg, "unused1b = %d\n", hdr.unused1b); fprintf(fcfg, "unused2 = %d\n", hdr.unused2); fprintf(fcfg, "notes = \n\"%s\"\n\n\n", hdr.notes); /* write families */ strcpy(fname, "mkdir "); strcat(fname, dumpdir); strcat(fname, "/families"); system(fname); strcpy(fbase, dumpdir); strcat(fbase, "/families/"); p = fbase + strlen(fbase); fprintf(fcfg, "# list of device family files\n"); fprintf(fcfg, "families = {\n"); for (i = 0; i < hdr.num_families; i++) { special_cat(p, families[i].name); strcat(fbase, ".fam"); printf("filename : \"%s\"\n", fbase); fprintf(fcfg, "\t\"%s\",\n", valid_string(fbase, g_tmp)); if ((f = fopen(fbase, "w+")) == NULL) { printf("error: cannot create file\n"); return -1; } print_family(f, &families[i]); fclose(f); } fprintf(fcfg, "}\n\n"); /* write devices */ strcpy(fname, "mkdir "); strcat(fname, dumpdir); strcat(fname, "/devices"); system(fname); strcpy(fbase, dumpdir); strcat(fbase, "/devices/"); p = fbase + strlen(fbase); fprintf(fcfg, "# list of device files\n"); fprintf(fcfg, "devices = {\n"); for (i = 0; i < hdr.num_devices; i++) { special_cat(p, devices[i].part_name); strcat(fbase, ".dev"); printf("filename : \"%s\"\n", fbase); fprintf(fcfg, "\t\"%s\",\n", valid_string(fbase, g_tmp)); if ((f = fopen(fbase, "w+")) == NULL) { printf("error: cannot create file\n"); return -1; } print_device(f, &devices[i]); fclose(f); } fprintf(fcfg, "}\n\n"); /* write scripts */ strcpy(fname, "mkdir "); strcat(fname, dumpdir); strcat(fname, "/scripts"); system(fname); strcpy(fbase, dumpdir); strcat(fbase, "/scripts/"); p = fbase + strlen(fbase); fprintf(fcfg, "# list of script files\n"); fprintf(fcfg, "scripts = {\n"); for (i = 0; i < hdr.num_scripts; i++) { special_cat(p, scripts[i].name); strcat(fbase, ".scr"); printf("filename : \"%s\"\n", fbase); fprintf(fcfg, "\t\"%s\",\n", valid_string(fbase, g_tmp)); if ((f = fopen(fbase, "w+")) == NULL) { printf("error: cannot create file\n"); return -1; } print_script(f, &scripts[i]); fclose(f); } fprintf(fcfg, "}"); fclose(fcfg); return 0; }
void test_VIDIOC_QUERYCAP() { int ret; struct v4l2_capability cap; struct v4l2_capability cap2; memset(&cap, 0xff, sizeof(cap)); ret = ioctl(get_video_fd(), VIDIOC_QUERYCAP, &cap); dprintf("VIDIOC_QUERYCAP, ret=%i\n", ret); dprintf("\tcap = { .driver = \"%s\", .card = \"%s\", " ".bus_info = \"%s\", " ".version = %u.%u.%u, " ".capabilities = 0x%X, " ".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X } }\n", cap.driver, cap.card, cap.bus_info, (cap.version >> 16) & 0xFF, (cap.version >> 8) & 0xFF, cap.version & 0xFF, cap.capabilities, cap.reserved[0], cap.reserved[1], cap.reserved[2], cap.reserved[3] ); /* This ioctl must be implemented by ALL drivers */ CU_ASSERT_EQUAL(ret, 0); if (ret == 0) { CU_ASSERT(0 < strlen( (char*)cap.driver) ); CU_ASSERT(valid_string((char*)cap.driver, sizeof(cap.driver))); CU_ASSERT(0 < strlen( (char*)cap.card) ); CU_ASSERT(valid_string((char*)cap.card, sizeof(cap.card))); /* cap.bus_info is allowed to be an empty string ("") if no * is info available */ CU_ASSERT(valid_string((char*)cap.bus_info, sizeof(cap.bus_info))); //CU_ASSERT_EQUAL(cap.version, ?); CU_ASSERT(valid_capabilities(cap.capabilities)); CU_ASSERT_EQUAL(cap.reserved[0], 0); CU_ASSERT_EQUAL(cap.reserved[1], 0); CU_ASSERT_EQUAL(cap.reserved[2], 0); CU_ASSERT_EQUAL(cap.reserved[3], 0); /* Check if the unused bytes of the driver, card and bus_info * strings are also filled with zeros. Also check if there is * any padding byte between any two fields then this padding * byte is also filled with zeros. */ memset(&cap2, 0, sizeof(cap2)); strncpy((char*)cap2.driver, (char*)cap.driver, sizeof(cap2.driver)); strncpy((char*)cap2.card, (char*)cap.card, sizeof(cap2.card)); strncpy((char*)cap2.bus_info, (char*)cap.bus_info, sizeof(cap2.bus_info)); cap2.version = cap.version; cap2.capabilities = cap.capabilities; CU_ASSERT_EQUAL(memcmp(&cap, &cap2, sizeof(cap)), 0); } }
int process_file(FILE *ifp) { char *ibuf, *config = NULL; byte **rom = NULL; /* pointers to ROM images */ byte *data = NULL; /* data accumulators */ int line = 0, first = 1, nroms = 0, abits = 0, length = 0, res = 0; int ix; /* Allocate space to read strings into */ if((ibuf = calloc(MAXLINE + 1, sizeof(char))) == NULL) { fprintf(stderr, "Insufficient memory to process file\n"); return 1; /* out of memory */ } /* Read strings from the input file */ while(read_line(ifp, ibuf, MAXLINE)) { ++line; strip_comment(ibuf); /* Blank lines are skipped in all cases */ if(is_blank(ibuf)) continue; strip_whitespace(ibuf); /* When we see the first line, we need to accumulate some other info we're going to need later. This includes the number of address bits (abits), and the number of ROMs (nroms). We also need to save a copy of the configuration line for later, since ibuf will be overwritten with each line that is consumed. We also range-check the values of abits and nroms, and allocate memory for the ROM images we will build during the reading of the rest of the file. We save the length of the configuration line (length) so that we can syntax check subsequent lines in an efficent manner. */ if(first) { /* Check structural validity of configuration line */ if(!valid_string(ibuf, "0123456789Aa")) { fprintf(stderr, "Line %d: invalid character in configuration\n", line); res = 1; goto CLEANUP; } /* Count number of ROM cells and address (state) bits */ nroms = count_roms(ibuf); abits = count_addr(ibuf); /* Complain if we didn't get at least 1 ROM, or if we got too many */ if(nroms < 1) { fprintf(stderr, "Line %d: must specify at least 1 ROM number\n", line); res = 2; goto CLEANUP; } else if(nroms > NUM_ROMS) { fprintf(stderr, "Line %d: cannot specify more than %d ROMs\n", line, NUM_ROMS); res = 2; goto CLEANUP; } /* Complain if we got no address bits, or more than MAXBITS */ if(abits < 1 || abits > MAXBITS) { fprintf(stderr, "Line %d: must have between 1-%d state bits\n", line, MAXBITS); res = 3; goto CLEANUP; } /* Okay, the config is alright, save it for later ... */ if((config = copy_string(ibuf)) == NULL) { fprintf(stderr, "Insufficient memory to process file\n"); res = 1; goto CLEANUP; } /* Hang onto the length, we'll need it later */ length = strlen(config); /* Allocate space for the ROMs and their accumulators */ if(!alloc_roms(&rom, nroms, config, abits)) { fprintf(stderr, "Insufficient memory to process file\n"); res = 1; goto CLEANUP; } if((data = calloc(nroms, sizeof(byte))) == NULL) { fprintf(stderr, "Insufficient memory to process file\n"); res = 1; goto CLEANUP; } first = 0; continue; } /* end if(first) */ /* Translate output "don't care" values to regular bits */ translate(ibuf, OUTPUT_DC, g_odcv); /* Anything bad left in the string? */ if(!valid_string(ibuf, "01Xx")) { fprintf(stderr, "Line %d: invalid character in data\n", line); res = 1; goto CLEANUP; } /* Make sure we got enough fields to satisfy the template */ if(strlen(ibuf) != length) { fprintf(stderr, "Line %d: wrong number of fields (wanted %u, got %u)\n", line, (unsigned) length, (unsigned) strlen(ibuf)); res = 4; goto CLEANUP; } /* Grab all the data out of the line, escaping on error */ if(!parse_data(ibuf, line, config, abits, data)) { res = 5; goto CLEANUP; } /* Write the data into the ROM images. We know which ROMs to use by checking the pointers in the ROM image array, and the accumulator is already set to go */ for(ix = 0; ix < nroms; ix++) { if(rom[ix]) { write_range(rom[ix], ibuf, abits, data[ix]); } } /* Clear out accumulators for the next round */ memset(data, 0, nroms); } /* end while(read_line(...)) */ /* If we didn't get a first line at all, the file was logically empty (i.e., not even a configuration!) */ if(first) { fprintf(stderr, "No configuration line was found\n"); res = 7; } else { /* Having accumulated all the data into the ROM images, we now will dump them out into the appropriate files */ if(!dump_roms(rom, nroms, abits, g_fmt)) res = 6; } CLEANUP: free(ibuf); if(config) free(config); if(rom) { free_roms(rom, nroms); free(rom); } if(data) free(data); return res; } /* end process_file() */
void test_VIDIOC_ENUMINPUT() { int ret_enum, errno_enum; struct v4l2_input input; struct v4l2_input input2; __u32 i; i = 0; do { memset(&input, 0xff, sizeof(input)); input.index = i; ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMINPUT, &input); errno_enum = errno; dprintf("\t%s:%u: VIDIOC_ENUMINPUT, ret_enum=%i, errno_enum=%i\n", __FILE__, __LINE__, ret_enum, errno_enum); if (ret_enum == 0) { CU_ASSERT_EQUAL(ret_enum, 0); CU_ASSERT_EQUAL(input.index, i); CU_ASSERT(0 < strlen( (char*)input.name )); CU_ASSERT(valid_string((char*)input.name, sizeof(input.name))); //CU_ASSERT_EQUAL(input.type, ?); //CU_ASSERT_EQUAL(input.audioset, ?); //CU_ASSERT_EQUAL(input.tuner, ?); CU_ASSERT(valid_v4l2_std_id(input.std)); //CU_ASSERT_EQUAL(input.status, ?); CU_ASSERT_EQUAL(input.reserved[0], 0); CU_ASSERT_EQUAL(input.reserved[1], 0); CU_ASSERT_EQUAL(input.reserved[2], 0); CU_ASSERT_EQUAL(input.reserved[3], 0); /* Check if the unused bytes of the name string are * also filled with zeros. Also check if there is any * padding byte between any two fields then this * padding byte is also filled with zeros. */ memset(&input2, 0, sizeof(input2)); input2.index = input.index; strncpy((char*)input2.name, (char*)input.name, sizeof(input2.name)); input2.type = input.type; input2.audioset = input.audioset; input2.tuner = input.tuner; input2.std = input.std; input2.status = input.status; CU_ASSERT_EQUAL(memcmp(&input, &input2, sizeof(input)), 0); show_v4l2_input(&input); } else { CU_ASSERT_EQUAL(ret_enum, -1); CU_ASSERT_EQUAL(errno_enum, EINVAL); memset(&input2, 0xff, sizeof(input2)); input2.index = i; CU_ASSERT_EQUAL(memcmp(&input, &input2, sizeof(input)), 0); } i++; } while (ret_enum == 0); }
bool Student::valid_student() const { return valid_string(GetName()) && valid_string(GetSurname()) && valid_grade(); }
/* * syscall_execve * * Implements the execve system call. This effectively does a "brain transplant" * on a process by arranging for it to run a different program to what it was * previously. This is achieved by loading the new program from the file system, * placing a copy in the process's text segment, and changing the instruction * pointer of the process to point to the first instruction of the loaded * executable file. * * In addition to loading a new program, this call is also responsible for passing * command line arguments to the new program. This is done by using the memory * at the bottom of the stack (actually the highest address, since the stack grows * downwards), in which the array of strings corresponding to argv is placed. The * argv and argc values are placed at the top of the stack, so that the main * function will be able to access them as arguments. */ int syscall_execve(const char *filename, char *const argv[], char *const envp[], regs * r) { process *proc = current_process; /* * Verify that the filename and all of the pointers within argc arg valid * (i.e. completely reside in the process's address space) */ if (!valid_string(filename)) return -EFAULT; unsigned int argno = 0; if (NULL != argv) { while (1) { if (!valid_pointer(argv, (argno + 1) * sizeof(char *))) return -EFAULT; if (NULL == argv[argno]) break; if (!valid_string(argv[argno])) return -EFAULT; argno++; } } /* * Check that the specified executable file actually exists, and find out its * location within the file system */ directory_entry *entry; int res; if (0 > (res = get_directory_entry(filesystem, filename, &entry))) return res; if (TYPE_DIR == entry->type) return -EISDIR; /* * Calculate number of arguments and amount of space needed to store them */ unsigned int argc = 0; unsigned int argslen = 0; for (argc = 0; argv && argv[argc]; argc++) argslen += strlen(argv[argc]) + 1; /* * Allocate a temporary buffer in which to store the argument data. This will * later be copied to the process's stack. The reason we can't do this * in-place is that doing so would risk overwriting some of the data we are * copying from. */ unsigned int argdata_size = argslen + argc * sizeof(char *) + 2 * sizeof(int); char *argdata = kmalloc(argdata_size); char **newargv = (char **)(argdata + 8); /* * Work backwards through the allocated buffer, copying in the strings one- * by-one */ unsigned int pos = argdata_size; for (argno = 0; argno < argc; argno++) { unsigned int nbytes = strlen(argv[argno]) + 1; pos -= nbytes; memmove(&argdata[pos], argv[argno], nbytes); newargv[argno] = (char *)(PROCESS_STACK_BASE - argdata_size + pos); } /* * Set argc and argv as the top two words on the stack. These are the values * that main will see passed in as its parameters. */ *(unsigned int *)(argdata + 0) = argc; *(unsigned int *)(argdata + 4) = PROCESS_STACK_BASE - argdata_size + 8; /* * Unmap the existing text segment */ disable_paging(); unsigned int addr; for (addr = proc->text_start; addr < proc->text_end; addr += PAGE_SIZE) unmap_and_free_page(proc->pdir, addr); for (addr = proc->data_start; addr < proc->data_end; addr += PAGE_SIZE) unmap_and_free_page(proc->pdir, addr); /* * Resize text and data segments to 0 bytes each */ proc->text_start = PROCESS_TEXT_BASE; proc->text_end = PROCESS_TEXT_BASE; proc->data_start = PROCESS_DATA_BASE; proc->data_end = PROCESS_DATA_BASE; /* * Load in the text segment from the executable file */ char *data = filesystem + entry->location; for (pos = 0; pos < entry->size; pos += PAGE_SIZE) { proc->text_end = proc->text_start + pos; void *page = alloc_page(); if (PAGE_SIZE <= entry->size - pos) memmove(page, &data[pos], PAGE_SIZE); else memmove(page, &data[pos], entry->size - pos); map_page(proc->pdir, proc->text_end, (unsigned int)page, PAGE_USER, PAGE_READ_WRITE); } proc->text_end = proc->text_start + pos; enable_paging(current_process->pdir); /* * Copy the command line argument data we set up above to the process's * stack */ memmove((void *)(PROCESS_STACK_BASE - argdata_size), argdata, argdata_size); kfree(argdata); /* * Set up the process's saved register state so that when it resumes * execution, it will start from the beginning of the loaded code. */ init_regs(r, PROCESS_STACK_BASE - argdata_size, (void *)current_process->text_start); return 0; }
void test_VIDIOC_ENUMAUDOUT() { int ret_enum, errno_enum; struct v4l2_audioout audioout; struct v4l2_audioout audioout2; __u32 i; i = 0; do { memset(&audioout, 0xff, sizeof(audioout)); audioout.index = i; ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDOUT, &audioout); errno_enum = errno; dprintf("\tVIDIOC_ENUMAUDOUT, ret_enum=%i, errno_enum=%i\n", ret_enum, errno_enum); if (ret_enum == 0) { CU_ASSERT_EQUAL(ret_enum, 0); CU_ASSERT_EQUAL(audioout.index, i); CU_ASSERT(0 < strlen( (char*)audioout.name )); CU_ASSERT(valid_string((char*)audioout.name, sizeof(audioout.name))); //CU_ASSERT_EQUAL(audioout.capability, ?); //CU_ASSERT_EQUAL(audioout.mode, ?); CU_ASSERT_EQUAL(audioout.reserved[0], 0); CU_ASSERT_EQUAL(audioout.reserved[1], 0); /* Check if the unused bytes of the name string are * also filled with zeros. Also check if there is any * padding byte between any two fields then this * padding byte is also filled with zeros. */ memset(&audioout2, 0, sizeof(audioout2)); audioout2.index = audioout.index; strncpy((char*)audioout2.name, (char*)audioout.name, sizeof(audioout2.name)); audioout2.capability = audioout.capability; audioout2.mode = audioout.mode; CU_ASSERT_EQUAL(memcmp(&audioout, &audioout2, sizeof(audioout)), 0); dprintf("\taudioout = {.index=%u, .name=\"%s\", " ".capability=0x%X, .mode=0x%X, " ".reserved[]={ 0x%X, 0x%X } }\n", audioout.index, audioout.name, audioout.capability, audioout.mode, audioout.reserved[0], audioout.reserved[1] ); } else { CU_ASSERT_EQUAL(ret_enum, -1); CU_ASSERT_EQUAL(errno_enum, EINVAL); /* check whether the structure is untouched */ memset(&audioout2, 0xff, sizeof(audioout2)); audioout2.index = i; CU_ASSERT_EQUAL(memcmp(&audioout, &audioout2, sizeof(audioout)), 0); } i++; } while (ret_enum == 0); }
void test_VIDIOC_QUERYCTRL_private() { int ret_query, errno_query; struct v4l2_queryctrl queryctrl; struct v4l2_queryctrl queryctrl2; __u32 i; i = V4L2_CID_PRIVATE_BASE; do { memset(&queryctrl, 0xff, sizeof(queryctrl)); queryctrl.id = i; ret_query = ioctl(get_video_fd(), VIDIOC_QUERYCTRL, &queryctrl); errno_query = errno; dprintf("\t%s:%u: VIDIOC_QUERYCTRL, id=%u (V4L2_CID_BASE+%i), ret_query=%i, errno_query=%i\n", __FILE__, __LINE__, i, i-V4L2_CID_BASE, ret_query, errno_query); if (ret_query == 0) { CU_ASSERT_EQUAL(ret_query, 0); CU_ASSERT_EQUAL(queryctrl.id, i); CU_ASSERT(0 < strlen( (char*)queryctrl.name )); CU_ASSERT(valid_string((char*)queryctrl.name, sizeof(queryctrl.name))); CU_ASSERT(valid_control_type(queryctrl.type)); switch (queryctrl.type) { case V4L2_CTRL_TYPE_INTEGER: /* min < max, because otherwise this control makes no sense */ CU_ASSERT(queryctrl.minimum < queryctrl.maximum); CU_ASSERT(0 < queryctrl.step); CU_ASSERT(queryctrl.minimum <= queryctrl.default_value); CU_ASSERT(queryctrl.default_value <= queryctrl.maximum); break; case V4L2_CTRL_TYPE_BOOLEAN: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 1); CU_ASSERT_EQUAL(queryctrl.step, 1); CU_ASSERT((queryctrl.default_value == 0) || (queryctrl.default_value == 1)); break; case V4L2_CTRL_TYPE_MENU: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT(queryctrl.minimum <= queryctrl.default_value); CU_ASSERT_EQUAL(queryctrl.step, 1); CU_ASSERT(queryctrl.minimum <= queryctrl.default_value); CU_ASSERT(queryctrl.default_value <= queryctrl.maximum); break; case V4L2_CTRL_TYPE_BUTTON: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 0); CU_ASSERT_EQUAL(queryctrl.step, 0); CU_ASSERT_EQUAL(queryctrl.default_value, 0); break; case V4L2_CTRL_TYPE_INTEGER64: /* fallthrough */ case V4L2_CTRL_TYPE_CTRL_CLASS: /* These parameters are defined as n/a by V4L2, so * they should be filled with zeros, the same like * the reserved fields. */ CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 0); CU_ASSERT_EQUAL(queryctrl.step, 0); CU_ASSERT_EQUAL(queryctrl.default_value, 0); break; default: CU_ASSERT_EQUAL(queryctrl.minimum, 0); CU_ASSERT_EQUAL(queryctrl.maximum, 0); CU_ASSERT_EQUAL(queryctrl.step, 0); CU_ASSERT_EQUAL(queryctrl.default_value, 0); } CU_ASSERT(valid_control_flag(queryctrl.flags)); CU_ASSERT_EQUAL(queryctrl.reserved[0], 0); CU_ASSERT_EQUAL(queryctrl.reserved[1], 0); /* Check if the unused bytes of the name string are * also filled with zeros. Also check if there is any * padding byte between any two fields then this * padding byte is also filled with zeros. */ memset(&queryctrl2, 0, sizeof(queryctrl2)); queryctrl2.id = queryctrl.id; queryctrl2.type = queryctrl.type; strncpy((char*)queryctrl2.name, (char*)queryctrl.name, sizeof(queryctrl2.name)); queryctrl2.minimum = queryctrl.minimum; queryctrl2.maximum = queryctrl.maximum; queryctrl2.step = queryctrl.step; queryctrl2.default_value = queryctrl.default_value; queryctrl2.flags = queryctrl.flags; CU_ASSERT_EQUAL(memcmp(&queryctrl, &queryctrl2, sizeof(queryctrl)), 0); dprintf("\tqueryctrl = {.id=%u, .type=%i, .name=\"%s\", " ".minimum=%i, .maximum=%i, .step=%i, " ".default_value=%i, " ".flags=0x%X, " ".reserved[]={ 0x%X, 0x%X } }\n", queryctrl.id, queryctrl.type, queryctrl.name, queryctrl.minimum, queryctrl.maximum, queryctrl.step, queryctrl.default_value, queryctrl.flags, queryctrl.reserved[0], queryctrl.reserved[1] ); } else { CU_ASSERT_EQUAL(ret_query, -1); CU_ASSERT_EQUAL(errno_query, EINVAL); memset(&queryctrl2, 0xff, sizeof(queryctrl2)); queryctrl2.id = i; CU_ASSERT_EQUAL(memcmp(&queryctrl, &queryctrl2, sizeof(queryctrl)), 0); } } while (ret_query == 0); }