xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XKit / Utilities / CHelpers.swift
CHelpers.swift28 lines · 765 BRaw
| 1 | // |
| 2 | // CHelpers.swift |
| 3 | // XKit |
| 4 | // |
| 5 | // Created by Kabir Oberai on 13/10/19. |
| 6 | // Copyright © 2019 Kabir Oberai. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import Foundation |
| 10 | import CXKit |
| 11 | |
| 12 | package var stdoutSafe: UnsafeMutablePointer<FILE> { |
| 13 | get_stdout() |
| 14 | } |
| 15 | |
| 16 | extension Data { |
| 17 | init?(deallocator: Deallocator = .free, acceptor: (inout Int) -> UnsafeMutableRawPointer?) { |
| 18 | var count = 0 |
| 19 | guard let bytes = acceptor(&count) else { return nil } |
| 20 | self.init(bytesNoCopy: bytes, count: count, deallocator: deallocator) |
| 21 | } |
| 22 | |
| 23 | init(deallocator: Deallocator = .free, acceptor: (inout Int) -> UnsafeMutableRawPointer) { |
| 24 | var count = 0 |
| 25 | let bytes = acceptor(&count) |
| 26 | self.init(bytesNoCopy: bytes, count: count, deallocator: deallocator) |
| 27 | } |
| 28 | } |