Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
appstore-distribution ▾

xtool.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
9import Foundation
10import CXKit
11
12package var stdoutSafe: UnsafeMutablePointer<FILE> {
13 get_stdout()
14}
15
16extension 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}