int hashify_write_file(stream_t* generated_file, string_t output_filename) { bool need_update = false; stream_t* output_file = 0; int result = HASHIFY_RESULT_OK; output_file = stream_open(STRING_ARGS(output_filename), STREAM_OUT | STREAM_IN); if (!output_file) { need_update = true; output_file = stream_open(STRING_ARGS(output_filename), STREAM_OUT); if (!output_file) { log_warnf(0, WARNING_INVALID_VALUE, STRING_CONST("Unable to open output file: %.*s"), STRING_FORMAT(output_filename)); return HASHIFY_RESULT_MISSING_OUTPUT_FILE; } } if (!need_update) need_update = !uint128_equal(stream_md5(generated_file), stream_md5(output_file)); if (need_update) { char local_buffer[1024]; size_t read = 0; size_t written = 0; uint64_t total_written = 0; stream_seek(generated_file, 0, STREAM_SEEK_BEGIN); stream_seek(output_file, 0, STREAM_SEEK_BEGIN); while (!stream_eos(generated_file)) { read = stream_read(generated_file, local_buffer, 1024); if (!read) break; written = stream_write(output_file, local_buffer, read); total_written += written; if (written != read) { log_errorf(0, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to write to output file '%.*s': %" PRIsize " of %" PRIsize " bytes written"), STRING_FORMAT(output_filename), written, read); result = HASHIFY_RESULT_OUTPUT_FILE_WRITE_FAIL; break; } } if (result == HASHIFY_RESULT_OK) { stream_truncate(output_file, (size_t)total_written); log_infof(0, STRING_CONST(" wrote %.*s : %" PRIu64 " bytes"), STRING_FORMAT(output_filename), total_written); } } else { log_info(0, STRING_CONST(" hash file already up to date")); } stream_deallocate(output_file); return result; }
int bin2hex_process_files( char const* const* input, char const* const* output, int columns ) { int result = BIN2HEX_RESULT_OK; unsigned int ifile, files_size; for( ifile = 0, files_size = array_size( input ); ( result == BIN2HEX_RESULT_OK ) && ( ifile < files_size ); ++ifile ) { char* input_filename = 0; char* output_filename = 0; stream_t* input_file = 0; stream_t* output_file = 0; input_filename = path_clean( string_clone( input[ifile] ), path_is_absolute( input[ifile] ) ); error_context_push( "parsing file", input_filename ); output_filename = path_clean( string_clone( output[ifile] ), path_is_absolute( output[ifile] ) ); log_infof( 0, "bin2hex %s -> %s", input_filename, output_filename ); input_file = stream_open( input_filename, STREAM_IN | STREAM_BINARY ); if( !input_file ) { log_warnf( 0, WARNING_BAD_DATA, "Unable to open input file: %s", input_filename ); result = BIN2HEX_RESULT_MISSING_INPUT_FILE; } else { output_file = stream_open( output_filename, STREAM_OUT ); if( !output_file ) { log_warnf( 0, WARNING_BAD_DATA, "Unable to open output file: %s", output_filename ); result = BIN2HEX_RESULT_UNABLE_TO_OPEN_OUTPUT_FILE; } } if( input_file && output_file ) result = bin2hex_process_file( input_file, output_file, columns ); stream_deallocate( input_file ); stream_deallocate( output_file ); string_deallocate( output_filename ); error_context_pop(); string_deallocate( input_filename ); } if( ( result == BIN2HEX_RESULT_OK ) && ( files_size > 0 ) ) log_info( 0, "All files generated" ); return result; }
int memory_stream_open(stream_t **stream, char *bytes, size_t size, stream_access_t access) { memory_stream_context_t *msc; int err; if (bytes == NULL) return -EINVAL; msc = os_malloc(sizeof(memory_stream_context_t)); if (msc == NULL) return -ENOMEM; msc->bytes = bytes; msc->size = size; msc->ofs = 0; err = stream_open(stream, msc, &memory_stream_ops, access); if (err != 0) { os_free(msc); return err; } return 0; }
static bool try_open(struct MPContext *mpctx, char *filename) { struct bstr bfilename = bstr0(filename); // Avoid trying to open itself or another .cue file. Best would be // to check the result of demuxer auto-detection, but the demuxer // API doesn't allow this without opening a full demuxer. if (bstr_case_endswith(bfilename, bstr0(".cue")) || bstrcasecmp(bstr0(mpctx->demuxer->filename), bfilename) == 0) return false; struct stream *s = stream_open(filename, mpctx->opts); if (!s) return false; struct demuxer *d = demux_open(s, NULL, NULL, mpctx->opts); // Since .bin files are raw PCM data with no headers, we have to explicitly // open them. Also, try to avoid to open files that are most likely not .bin // files, as that would only play noise. Checking the file extension is // fragile, but it's about the only way we have. // TODO: maybe also could check if the .bin file is a multiple of the Audio // CD sector size (2352 bytes) if (!d && bstr_case_endswith(bfilename, bstr0(".bin"))) { mp_msg(MSGT_CPLAYER, MSGL_WARN, "CUE: Opening as BIN file!\n"); d = demux_open(s, "rawaudio", NULL, mpctx->opts); } if (d) { add_source(mpctx, d); return true; } mp_msg(MSGT_CPLAYER, MSGL_ERR, "Could not open source '%s'!\n", filename); free_stream(s); return false; }
var File_New(var self, var_list vl) { FileData* fd = cast(self, File); const char* filename = as_str(var_list_get(vl)); const char* access = as_str(var_list_get(vl)); stream_open(self, filename, access); return self; }
static void asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs) { char *href; stream_t* stream; if(parser->deep > 0) return; href = asx_get_attrib("HREF",_attribs); if(href == NULL) { asx_warning_attrib_required(parser,"ENTRYREF" ,"HREF" ); return; } stream=stream_open(href, NULL); if(!stream) { mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Can't open playlist %s\n",href); free(href); return; } mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Not recursively loading playlist %s\n",href); free_stream(stream); free(href); //mp_msg(MSGT_PLAYTREE,MSGL_INFO,"Need to implement entryref\n"); }
int main(int argc, char* argv[]) { size_t n = 0x200000; double rate = 1; zfp_field* field; uint insize; zfp_stream* zfp; bitstream* stream; void* buffer; size_t bytes; clock_t c; double time; uint i; switch (argc) { case 3: sscanf(argv[2], "%zu", &n); /* FALLTHROUGH */ case 2: sscanf(argv[1], "%lf", &rate); break; } /* declare array to compress */ field = zfp_field_3d(NULL, zfp_type_double, 4, 4, 4 * n); insize = n * sizeof(block); /* allocate storage for compressed bit stream */ zfp = zfp_stream_open(NULL); zfp_stream_set_rate(zfp, rate, zfp_field_type(field), zfp_field_dimensionality(field), 0); bytes = zfp_stream_maximum_size(zfp, field); buffer = malloc(bytes); stream = stream_open(buffer, bytes); zfp_stream_set_bit_stream(zfp, stream); zfp_field_free(field); /* compress */ c = clock(); for (i = 0; i < n; i++) zfp_encode_block_double_3(zfp, (const double*)block); zfp_stream_flush(zfp); time = (double)(clock() - c) / CLOCKS_PER_SEC; printf("encode in=%u out=%u %.0f MB/s\n", insize, (uint)stream_size(stream), insize / (1024 * 1024 * time)); /* decompress */ zfp_stream_rewind(zfp); c = clock(); for (i = 0; i < n; i++) { double a[64]; zfp_decode_block_double_3(zfp, a); } time = (double)(clock() - c) / CLOCKS_PER_SEC; printf("decode in=%u out=%u %.0f MB/s\n", (uint)stream_size(stream), insize, insize / (1024 * 1024 * time)); zfp_stream_close(zfp); stream_close(stream); free(buffer); return 0; }
bool FFVideo::open(const char *url) { _first = true; close(); _ctx = stream_open(url, NULL); return _ctx != nullptr; }
static int tokenizer_open(server *srv, tokenizer_t *t, buffer *basedir, const char *fn) { if (buffer_is_empty(basedir) || (fn[0] == '/' || fn[0] == '\\') || (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) { t->file = buffer_init_string(fn); } else { t->file = buffer_init_buffer(basedir); buffer_append_string(t->file, fn); } if (0 != stream_open(&(t->s), t->file)) { log_error_write(srv, __FILE__, __LINE__, "sbss", "opening configfile ", t->file, "failed:", strerror(errno)); buffer_free(t->file); return -1; } t->input = t->s.start; t->offset = 0; t->size = t->s.size; t->line = 1; t->line_pos = 1; t->in_key = 1; t->in_brace = 0; t->in_cond = 0; return 0; }
struct resource * fdstream_resource (const char * path, int fd, const char * content_type) { struct fdstream * st; if ((st = calloc (1, sizeof(*st))) == NULL) return NULL; st->path = x_strdup (path); if (st->path == NULL) { free (st); return NULL; } st->content_type = x_strdup (content_type); if (st->content_type == NULL) { free (st); free ((char *)st->path); return NULL; } st->stream = stream_open (fd); if (st->stream == NULL) { free (st); free ((char *)st->path); free ((char *)st->content_type); return NULL; } return resource_new (fdstream_check, fdstream_head, fdstream_body, fdstream_delete, st); }
int config_parse_file(server *srv, config_t *context, const char *fn) { tokenizer_t t; stream s; int ret; buffer *filename; if (buffer_is_empty(context->basedir) || (fn[0] == '/' || fn[0] == '\\') || (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) { filename = buffer_init_string(fn); } else { filename = buffer_init_buffer(context->basedir); buffer_append_string(filename, fn); } if (0 != stream_open(&s, filename)) { if (s.size == 0) { /* the file was empty, nothing to parse */ ret = 0; } else { log_error_write(srv, __FILE__, __LINE__, "sbss", "opening configfile ", filename, "failed:", strerror(errno)); ret = -1; } } else { tokenizer_init(&t, filename, s.start, s.size); ret = config_parse(srv, context, &t); } stream_close(&s); buffer_free(filename); return ret; }
static int pi433_open(struct inode *inode, struct file *filp) { struct pi433_device *device; struct pi433_instance *instance; mutex_lock(&minor_lock); device = idr_find(&pi433_idr, iminor(inode)); mutex_unlock(&minor_lock); if (!device) { pr_debug("device: minor %d unknown.\n", iminor(inode)); return -ENODEV; } instance = kzalloc(sizeof(*instance), GFP_KERNEL); if (!instance) return -ENOMEM; /* setup instance data*/ instance->device = device; instance->tx_cfg.bit_rate = 4711; // TODO: fill instance->tx_cfg; /* instance data as context */ filp->private_data = instance; stream_open(inode, filp); return 0; }
var File_New(var self, va_list* args) { FileData* fd = cast(self, File); const char* filename = va_arg(*args, const char*); const char* access = va_arg(*args, const char*); stream_open(self, filename, access); return self; }
int main(void) { struct stream *s; CURL *curl; CURLcode res; s = stream_new(ZOUT); stream_open(s, Z_BEST_COMPRESSION); curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, ZURL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) s); res = curl_easy_perform(curl); if (res != CURLE_OK) fprintf(stderr, "error: %s\n", curl_easy_strerror(res)); stream_close(s); if (s->error) fprintf(stderr, "error: stream is invalid\n"); curl_easy_cleanup(curl); curl_global_cleanup(); stream_del(s); return 0; }
// return value: // 0 = EOF or no stream found // 1 = successfully read a packet static int demux_mf_fill_buffer(demuxer_t *demuxer) { mf_t *mf = demuxer->priv; if (mf->curr_frame >= mf->nr_of_files) return 0; struct stream *entry_stream = NULL; if (mf->streams) entry_stream = mf->streams[mf->curr_frame]; struct stream *stream = entry_stream; if (!stream) { char *filename = mf->names[mf->curr_frame]; if (filename) stream = stream_open(filename, demuxer->opts); } if (stream) { stream_seek(stream, 0); bstr data = stream_read_complete(stream, NULL, MF_MAX_FILE_SIZE); if (data.len) { demux_packet_t *dp = new_demux_packet(data.len); memcpy(dp->buffer, data.start, data.len); dp->pts = mf->curr_frame / mf->sh->fps; dp->keyframe = true; demuxer_add_packet(demuxer, demuxer->streams[0], dp); } talloc_free(data.start); } if (stream && stream != entry_stream) free_stream(stream); mf->curr_frame++; return 1; }
int main(int argc, char **argv){ int ret; /* validate arguments */ if ( argc != 2 ){ fprintf(stderr, "usage: %s FILENAME\n", argv[0]); return 1; } /* load tracefile address */ const char* filename = argv[1]; stream_addr_t addr = STREAM_ADDR_INITIALIZER; stream_addr_str(&addr, filename, 0); /* open stream */ stream_t stream; if ( (ret=stream_open(&stream, &addr, NULL, 0)) != 0 ){ fprintf(stderr, "%s: %s\n", filename, caputils_error_string(ret)); return ret; } /* read packets */ while ( stream_read_cb(stream, handle_packet, NULL, NULL) == 0 ); /* close stream */ stream_close(stream); return 0; }
static int enable_cache(struct MPContext *mpctx, struct stream **stream, struct demuxer **demuxer, struct demuxer_params *params) { struct MPOpts *opts = mpctx->opts; if (opts->stream_cache_size <= 0) return 0; char *filename = talloc_strdup(NULL, (*demuxer)->filename); free_demuxer(*demuxer); free_stream(*stream); *stream = stream_open(filename, opts); if (!*stream) { talloc_free(filename); return -1; } stream_enable_cache_percent(stream, opts->stream_cache_size, opts->stream_cache_def_size, opts->stream_cache_min_percent, opts->stream_cache_seek_min_percent); *demuxer = demux_open(*stream, "mkv", params, opts); if (!*demuxer) { talloc_free(filename); free_stream(*stream); return -1; } talloc_free(filename); return 1; }
static int bcm63xx_wdt_open(struct inode *inode, struct file *file) { if (test_and_set_bit(0, &bcm63xx_wdt_device.inuse)) return -EBUSY; bcm63xx_wdt_start(); return stream_open(inode, file); }
int main( void ) { struct reader *pp_readers[3]; test_init(); #ifndef TEST_NET char psz_tmp_path[] = "/tmp/libvlc_XXXXXX"; char *psz_url; int i_tmp_fd; log( "Test random file with libc, and stream\n" ); i_tmp_fd = vlc_mkstemp( psz_tmp_path ); fill_rand( i_tmp_fd, RAND_FILE_SIZE ); assert( i_tmp_fd != -1 ); assert( asprintf( &psz_url, "file://%s", psz_tmp_path ) != -1 ); assert( ( pp_readers[0] = libc_open( psz_tmp_path ) ) ); assert( ( pp_readers[1] = stream_open( psz_url ) ) ); test( pp_readers, 2, NULL ); for( unsigned int i = 0; i < 2; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); free( psz_url ); close( i_tmp_fd ); #else log( "Test http url with stream\n" ); alarm( 0 ); if( !( pp_readers[0] = stream_open( HTTP_URL ) ) ) { log( "WARNING: can't test http url" ); return 0; } test( pp_readers, 1, HTTP_MD5 ); for( unsigned int i = 0; i < 1; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); #endif return 0; }
int obj_open(DAL_Context* ctx, int is_put, size_t chunk_offset, size_t content_length, uint8_t preserve_write_count, uint16_t timeout) { return stream_open(OS(ctx), is_put, chunk_offset, content_length, preserve_write_count, timeout); }
int main( void ) { struct reader *pp_readers[3]; test_init(); #ifndef TEST_NET char psz_file[PATH_MAX]; char *psz_url; log( "Test local file with libc, and stream\n" ); assert( realpath( FILE_PATH, psz_file ) == psz_file ); assert( asprintf( &psz_url, "file://%s", psz_file ) != -1 ); assert( ( pp_readers[0] = libc_open( psz_file ) ) ); assert( ( pp_readers[1] = stream_open( psz_url ) ) ); test( pp_readers, 2, FILE_MD5 ); for( unsigned int i = 0; i < 2; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); free( psz_url ); #else log( "Test http url with stream\n" ); alarm( 0 ); if( !( pp_readers[0] = stream_open( HTTP_URL ) ) ) { log( "WARNING: can't test http url" ); return 0; } test( pp_readers, 1, HTTP_MD5 ); for( unsigned int i = 0; i < 1; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); #endif return 0; }
// Update the tranfer state with new information static void transfer_stream_open(stream_type_t stream, uint32_t start_sector) { error_t status; util_assert(!file_transfer_state.stream_open); util_assert(start_sector != VFS_INVALID_SECTOR); vfs_mngr_printf("vfs_manager transfer_update_stream_open(stream=%i, start_sector=%i)\r\n", stream, start_sector); // Initialize the starting sector if it has not been set if (VFS_INVALID_SECTOR == file_transfer_state.start_sector) { file_transfer_state.start_sector = start_sector; if (start_sector != VFS_INVALID_SECTOR) { vfs_mngr_printf(" start_sector=%i\r\n", start_sector); } } // Initialize the stream if it has not been set if (STREAM_TYPE_NONE == file_transfer_state.stream) { file_transfer_state.stream = stream; if (stream != STREAM_TYPE_NONE) { vfs_mngr_printf(" stream=%i\r\n", stream); } } // Check - Starting sector must be the same if (start_sector != file_transfer_state.start_sector) { vfs_mngr_printf(" error: starting sector changed from %i to %i\r\n", file_transfer_state.start_sector, start_sector); transfer_update_state(ERROR_ERROR_DURING_TRANSFER); return; } // Check - stream must be the same if (stream != file_transfer_state.stream) { vfs_mngr_printf(" error: changed types during tranfer from %i to %i\r\n", stream, file_transfer_state.stream); transfer_update_state(ERROR_ERROR_DURING_TRANSFER); return; } // Open stream status = stream_open(stream); vfs_mngr_printf(" stream_open stream=%i ret %i\r\n", stream, status); if (ERROR_SUCCESS == status) { file_transfer_state.file_next_sector = start_sector; file_transfer_state.stream_open = true; file_transfer_state.stream_started = true; } transfer_update_state(status); }
static int fop_open(struct inode *inode, struct file *file) { /* Just in case we're already talking to someone... */ if (test_and_set_bit(0, &wdt_is_open)) return -EBUSY; if (nowayout) __module_get(THIS_MODULE); /* Good, fire up the show */ wdt_startup(); return stream_open(inode, file); }
int file_crc(const char *fname, unsigned long *result) { int err; imgtool_stream *f; f = stream_open(fname, OSD_FOPEN_READ); if (!f) return IMGTOOLERR_FILENOTFOUND; err = stream_crc(f, result); stream_close(f); return err; }
static int cmd_readsector(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; imgtool_image *img; imgtool_stream *stream = NULL; void *buffer = NULL; UINT32 size, track, head, sector; /* attempt to open image */ err = imgtool_image_open_byname(argv[0], argv[1], OSD_FOPEN_READ, &img); if (err) goto done; track = atoi(argv[2]); head = atoi(argv[3]); sector = atoi(argv[4]); err = imgtool_image_get_sector_size(img, track, head, sector, &size); if (err) goto done; buffer = malloc(size); if (!buffer) { err = IMGTOOLERR_OUTOFMEMORY; goto done; } err = imgtool_image_read_sector(img, track, head, sector, buffer, size); if (err) goto done; stream = stream_open(argv[5], OSD_FOPEN_WRITE); if (!stream) { err = (imgtoolerr_t)(IMGTOOLERR_FILENOTFOUND | IMGTOOLERR_SRC_NATIVEFILE); goto done; } stream_write(stream, buffer, size); done: if (buffer) free(buffer); if (stream) stream_close(stream); if (err) reporterror(err, c, argv[0], argv[1], NULL, NULL, 0); return err ? -1 : 0; }
RESOW_DECL_METHOD(setup_create_form,env,resp,db) { gchar *path; gchar *appname; resow_application_t *app; request_cgi_env_t env_a; GSList *i; path=http_response_html_escape_string(HTTP_QUERY_PARAMETER(env, "path")); appname=http_response_html_escape_string(HTTP_QUERY_PARAMETER(env, "app")); memset(&env_a, 0, sizeof(request_cgi_env_t)); app = application_load(appname, &env_a); if (app==NULL) { return HTTP_STATUS_BAD_REQUEST; } stream_open(resp, HTTP_STATUS_OK, 1); stream_printf(resp, "<html><head><title>Define new parameter for %s (at %s)</title></head>\n", app, path); stream_printf(resp, "<body>\n"); stream_printf(resp, "<h1>Define new parameter for %s (at %s)</h1>\n", appname, path); stream_printf(resp, "<table><form method=\"POST\">\n"); stream_printf(resp, "<tr><th></th><th>Parameter</th><th>Value</th></tr>\n"); stream_printf(resp, "<tr><td><input type=\"hidden\" name=\"path\" value=\"%s\"></input><input type=\"hidden\" name=\"app\" value=\"%s\"></input></td>\n", path, appname); i = app->parameters; stream_printf(resp, "<td><select name=\"param\"%s>\n", i==NULL? " disabled" : ""); while (i!=NULL) { stream_printf(resp, "\t<option>%s</option>\n", i->data); i=i->next; } stream_printf(resp, "</select></td>\n"); stream_printf(resp, "<td><input type=\"text\" name=\"value\"></input></td>\n"); stream_printf(resp, "</tr>\n"); stream_printf(resp, "<tr><td></td><td><input type=\"submit\" value=\"Add\"></td></td></tr>\n"); stream_printf(resp, "</form></table>\n"); if (app->parameters==NULL) stream_printf(resp, "<p>There are no parameters to set in application <tt>%s</tt></p>\n", app->name); stream_printf(resp, "</body></html>\n"); stream_close(resp); application_unload(app); g_free(path); g_free(appname); return HTTP_STATUS_OK; }
static int on_begin_headers_cb(nghttp2_session *ngh2, const nghttp2_frame *frame, void *userp) { /* This starts a new stream. */ int rv; (void)ngh2; rv = stream_open((h2_session *)userp, frame->hd.stream_id); if (rv != NGHTTP2_ERR_CALLBACK_FAILURE) { /* on_header_cb or on_frame_recv_cb will dectect that stream does not exist and submit RST_STREAM. */ return 0; } return NGHTTP2_ERR_CALLBACK_FAILURE; }
static void http_list_directory_footer(server *srv, connection *con, plugin_data *p, buffer *out) { UNUSED(srv); buffer_append_string_len(out, CONST_STR_LEN( "</tbody>\n" "</table>\n" "</div>\n" )); if (p->conf.show_readme) { stream s; /* if we have a README file, display it in <pre class="readme"></pre> */ buffer_copy_string_buffer(p->tmp_buf, con->physical.path); BUFFER_APPEND_SLASH(p->tmp_buf); buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("README.txt")); if (-1 != stream_open(&s, p->tmp_buf)) { if (p->conf.encode_readme) { buffer_append_string_len(out, CONST_STR_LEN("<pre class=\"readme\">")); buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML); buffer_append_string_len(out, CONST_STR_LEN("</pre>")); } else { buffer_append_string_len(out, s.start, s.size); } } stream_close(&s); } if(p->conf.auto_layout) { buffer_append_string_len(out, CONST_STR_LEN( "<div class=\"foot\">" )); if (p->conf.set_footer->used > 1) { buffer_append_string_buffer(out, p->conf.set_footer); } else if (buffer_is_empty(con->conf.server_tag)) { buffer_append_string_len(out, CONST_STR_LEN(PACKAGE_DESC)); } else { buffer_append_string_buffer(out, con->conf.server_tag); } buffer_append_string_len(out, CONST_STR_LEN( "</div>\n" "</body>\n" "</html>\n" )); } }
static int watchdog_open(struct inode *inode, struct file *file) { struct watchdog_core_data *wd_data; struct watchdog_device *wdd; bool hw_running; int err; /* Get the corresponding watchdog device */ if (imajor(inode) == MISC_MAJOR) wd_data = old_wd_data; else wd_data = container_of(inode->i_cdev, struct watchdog_core_data, cdev); /* the watchdog is single open! */ if (test_and_set_bit(_WDOG_DEV_OPEN, &wd_data->status)) return -EBUSY; wdd = wd_data->wdd; /* * If the /dev/watchdog device is open, we don't want the module * to be unloaded. */ hw_running = watchdog_hw_running(wdd); if (!hw_running && !try_module_get(wdd->ops->owner)) { err = -EBUSY; goto out_clear; } err = watchdog_start(wdd); if (err < 0) goto out_mod; file->private_data = wd_data; if (!hw_running) kref_get(&wd_data->kref); /* dev/watchdog is a virtual (and thus non-seekable) filesystem */ return stream_open(inode, file); out_mod: module_put(wd_data->wdd->ops->owner); out_clear: clear_bit(_WDOG_DEV_OPEN, &wd_data->status); return err; }
static void encode_2pass_prepare(struct encode_lavc_context *ctx, AVDictionary **dictp, AVStream *stream, AVCodecContext *codec, struct stream **bytebuf, const char *prefix) { if (!*bytebuf) { char buf[sizeof(ctx->avc->filename) + 12]; AVDictionaryEntry *de = av_dict_get(ctx->voptions, "flags", NULL, 0); snprintf(buf, sizeof(buf), "%s-%s-pass1.log", ctx->avc->filename, prefix); buf[sizeof(buf) - 1] = 0; if (value_has_flag(de ? de->value : "", "pass2")) { if (!(*bytebuf = stream_open(buf, ctx->global))) { MP_WARN(ctx, "%s: could not open '%s', " "disabling 2-pass encoding at pass 2\n", prefix, buf); codec->flags &= ~AV_CODEC_FLAG_PASS2; set_to_avdictionary(ctx, dictp, "flags", "-pass2"); } else { struct bstr content = stream_read_complete(*bytebuf, NULL, 1000000000); if (content.start == NULL) { MP_WARN(ctx, "%s: could not read '%s', " "disabling 2-pass encoding at pass 1\n", prefix, ctx->avc->filename); } else { content.start[content.len] = 0; codec->stats_in = content.start; } free_stream(*bytebuf); *bytebuf = NULL; } } if (value_has_flag(de ? de->value : "", "pass1")) { if (!(*bytebuf = open_output_stream(buf, ctx->global))) { MP_WARN(ctx, "%s: could not open '%s', disabling " "2-pass encoding at pass 1\n", prefix, ctx->avc->filename); set_to_avdictionary(ctx, dictp, "flags", "-pass1"); } } } }