/*! * \brief The returned value is a pointer to file. * * \param[in] name The name of the file to open. * \param[in] mods Different modes for opening file. * * \return A pointer to the object controlling the stream. * \return NULL (Open operation fails.) */ FILE *fdopen(int fd, const char *mods) { int flags; int i; FILE *file; if ((!mods) || (0 > fd)) { return NULL; } flags = parse_mods(mods); if (-1 == flags) { return NULL; } _STD_LOCK(); if (FOPEN_MAX > _files_cnt) { _files_cnt++; } else { _STD_UNLOCK(); return NULL; } _STD_UNLOCK(); file = (FILE*) malloc(sizeof(FILE)); if (NULL == file) { return NULL; } file->_MODE = _MODE_FOC; file->_BUF = &file->_CBUF; /* store flags to file structure */ file->_MODE |= flags; file->_FD = fd; _STD_LOCK(); for(i = 0; i < FOPEN_MAX; i++) { if (NULL == _files[i]) { _files[i] = file; break; } } _STD_UNLOCK(); return file; }
void load_mouse_resource (const Resource *res) { int bi, mi, a; int action_count; #ifdef DEBUG_HID_RESOURCE fprintf(stderr, "note mouse resource:\n"); resource_dump (res); #endif button_count = res->c; button_nums = (int *)malloc(res->c * sizeof(int)); mod_count = (int *)malloc(res->c * sizeof(int)); action_count = 0; for (bi=0; bi<res->c; bi++) { if (res->v[bi].value) action_count++; if (res->v[bi].subres) action_count += res->v[bi].subres->c; } mods = (unsigned int *)malloc(action_count * sizeof(int)); actions = (Resource **)malloc(action_count * sizeof(Resource*)); a = 0; for (bi=0; bi<res->c; bi++) { int button_num = button_name_to_num(res->v[bi].name); if (button_num < 0) continue; button_nums[bi] = button_num; mod_count[bi] = 0; if (res->v[bi].value) { mods[a] = 0; actions[a++] = res_wrap (res->v[bi].value); mod_count[bi] = 1; } if (res->v[bi].subres) { Resource *m = res->v[bi].subres; mod_count[bi] += m->c; for (mi=0; mi<m->c; mi++, a++) { switch (resource_type (m->v[mi])) { case 1: /* subres only */ mods[a] = 0; actions[a] = m->v[mi].subres; break; case 10: /* value only */ mods[a] = 0; actions[a] = res_wrap (m->v[mi].value); break; case 101: /* name = subres */ mods[a] = parse_mods (m->v[mi].name); actions[a] = m->v[mi].subres; break; case 110: /* name = value */ mods[a] = parse_mods (m->v[mi].name); actions[a] = res_wrap (m->v[mi].value); break; } } } } }
/*! * \brief The returned value is a pointer to file. * * \param[in] name The name of the file to open. * \param[in] mods Different modes for opening file. * * \return A pointer to the object controlling the stream. * \return NULL (Open operation fails.) */ FILE *fopen(const char *name, const char *mods) { int flags = 0; int i; FILE *file; if (!mods) { return NULL; } flags = parse_mods(mods); if (-1 == flags) { return NULL; } _STD_LOCK(); if (FOPEN_MAX > _files_cnt) { _files_cnt++; } else { _STD_UNLOCK(); return NULL; } _STD_UNLOCK(); file = (FILE*) malloc(sizeof(FILE)); if (NULL == file) { return NULL; } file->_MODE = _MODE_FOC; file->_BUF = &file->_CBUF; /* store flags to file structure */ file->_MODE |= flags; /* Call low lvel open on file */ file->_FD = _OPEN(name, flags, 0); if (0 > file->_FD) { free(file); _STD_LOCK(); _files_cnt--; _STD_UNLOCK(); return NULL; } _STD_LOCK(); for(i = 0; i < FOPEN_MAX; i++) { if (NULL == _files[i]) { _files[i] = file; break; } } _STD_UNLOCK(); return file; }