1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! A wrapper around LLVM's archive (.a) code
19 pub struct ArchiveRO {
24 /// Opens a static archive for read-only purposes. This is more optimized
25 /// than the `open` method because it uses LLVM's internal `Archive` class
26 /// rather than shelling out to `ar` for everything.
28 /// If this archive is used with a mutable method, then an error will be
30 pub fn open(dst: &Path) -> Option<ArchiveRO> {
32 let ar = dst.with_c_str(|dst| {
33 ::LLVMRustOpenArchive(dst)
38 Some(ArchiveRO { ptr: ar })
43 /// Reads a file in the archive
44 pub fn read<'a>(&'a self, file: &str) -> Option<&'a [u8]> {
46 let mut size = 0 as libc::size_t;
47 let ptr = file.with_c_str(|file| {
48 ::LLVMRustArchiveReadSection(self.ptr, file, &mut size)
53 Some(mem::transmute(raw::Slice {
62 impl Drop for ArchiveRO {
65 ::LLVMRustDestroyArchive(self.ptr);