From 24af20b79dc3dac6befb945772a0b19434f32f5d Mon Sep 17 00:00:00 2001 From: meh Date: Wed, 10 Jun 2015 22:03:25 +0200 Subject: [PATCH] format/context: do not use unstable to_cstring --- src/format/context.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/format/context.rs b/src/format/context.rs index 015d270..603c876 100644 --- a/src/format/context.rs +++ b/src/format/context.rs @@ -3,7 +3,7 @@ use std::ptr; use std::path::Path; use std::marker::PhantomData; -use libc::c_uint; +use libc::{c_char, c_uint}; use ffi::*; use ::{Error, Dictionary, Codec, Stream, Format, Packet}; @@ -208,10 +208,15 @@ impl<'a> Iterator for PacketIter<'a> { } } +// XXX: use to_cstring when stable +fn from_path>(path: &T) -> *const c_char { + CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap().as_ptr() +} + pub fn open>(path: &T) -> Result { unsafe { let mut ps = ptr::null_mut(); - let path = path.as_ref().as_os_str().to_cstring().unwrap().as_ptr(); + let path = from_path(path); let status = avformat_open_input(&mut ps, path, ptr::null_mut(), ptr::null_mut()); match status { @@ -232,7 +237,7 @@ pub fn open>(path: &T) -> Result { pub fn open_with>(path: &T, options: Dictionary) -> Result { unsafe { let mut ps = ptr::null_mut(); - let path = path.as_ref().as_os_str().to_cstring().unwrap().as_ptr(); + let path = from_path(path); let mut opts = options.take(); let status = avformat_open_input(&mut ps, path, ptr::null_mut(), &mut opts); @@ -257,7 +262,7 @@ pub fn open_as>(path: &T, format: &Format) -> Result>(path: &T, format: &Format, options: Dictiona if let &Format::Input(ref format) = format { unsafe { let mut ps = ptr::null_mut(); - let path = path.as_ref().as_os_str().to_cstring().unwrap().as_ptr(); + let path = from_path(path); let mut opts = options.take(); let status = avformat_open_input(&mut ps, path, format.as_ptr(), &mut opts);