]>
git.proxmox.com Git - rustc.git/blob - src/librustc_llvm/archive_ro.rs
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
16 use std
::ffi
::CString
;
20 pub struct ArchiveRO
{
25 /// Opens a static archive for read-only purposes. This is more optimized
26 /// than the `open` method because it uses LLVM's internal `Archive` class
27 /// rather than shelling out to `ar` for everything.
29 /// If this archive is used with a mutable method, then an error will be
31 pub fn open(dst
: &Path
) -> Option
<ArchiveRO
> {
33 let s
= CString
::from_slice(dst
.as_vec());
34 let ar
= ::LLVMRustOpenArchive(s
.as_ptr());
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 file
= CString
::from_slice(file
.as_bytes());
48 let ptr
= ::LLVMRustArchiveReadSection(self.ptr
, file
.as_ptr(),
53 Some(mem
::transmute(raw
::Slice
{
62 impl Drop
for ArchiveRO
{
65 ::LLVMRustDestroyArchive(self.ptr
);