Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2019 Google
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#pragma once
16
 
17
#include <stdbool.h>
18
#include <stdint.h>
19
#include <sys/cdefs.h>
20
 
21
// Required for 1P builds
22
#include <stddef.h>
23
#include <sys/types.h>
24
#include <unistd.h>
25
 
26
#if defined(__OBJC__)
27
#import <Foundation/Foundation.h>
28
#endif
29
 
30
__BEGIN_DECLS
31
 
32
typedef struct {
33
  int fd;
34
  int collectionDepth;
35
  bool needComma;
36
 
37
  bool bufferWrites;
38
  char* writeBuffer;
39
  size_t writeBufferLength;
40
 
41
  off_t writtenLength;
42
} FIRCLSFile;
43
typedef FIRCLSFile* FIRCLSFileRef;
44
 
45
#define CLS_FILE_MAX_STRING_LENGTH (10240)
46
#define CLS_FILE_HEX_BUFFER \
47
  (32)  // must be at least 2, and should be even (to account for 2 chars per hex value)
48
#define CLS_FILE_MAX_WRITE_ATTEMPTS (50)
49
 
50
extern const size_t FIRCLSWriteBufferLength;
51
 
52
// make sure to stop work if either FIRCLSFileInit... method returns false, because the FIRCLSFile
53
// struct will contain garbage data!
54
bool FIRCLSFileInitWithPath(FIRCLSFile* file, const char* path, bool bufferWrites);
55
bool FIRCLSFileInitWithPathMode(FIRCLSFile* file,
56
                                const char* path,
57
                                bool appendMode,
58
                                bool bufferWrites);
59
 
60
void FIRCLSFileFlushWriteBuffer(FIRCLSFile* file);
61
bool FIRCLSFileClose(FIRCLSFile* file);
62
bool FIRCLSFileCloseWithOffset(FIRCLSFile* file, off_t* finalSize);
63
bool FIRCLSFileIsOpen(FIRCLSFile* file);
64
 
65
bool FIRCLSFileLoopWithWriteBlock(const void* buffer,
66
                                  size_t length,
67
                                  ssize_t (^writeBlock)(const void* partialBuffer,
68
                                                        size_t partialLength));
69
bool FIRCLSFileWriteWithRetries(int fd, const void* buffer, size_t length);
70
 
71
// writing
72
void FIRCLSFileWriteSectionStart(FIRCLSFile* file, const char* name);
73
void FIRCLSFileWriteSectionEnd(FIRCLSFile* file);
74
 
75
void FIRCLSFileWriteHashStart(FIRCLSFile* file);
76
void FIRCLSFileWriteHashEnd(FIRCLSFile* file);
77
void FIRCLSFileWriteHashKey(FIRCLSFile* file, const char* key);
78
void FIRCLSFileWriteHashEntryUint64(FIRCLSFile* file, const char* key, uint64_t value);
79
void FIRCLSFileWriteHashEntryInt64(FIRCLSFile* file, const char* key, int64_t value);
80
void FIRCLSFileWriteHashEntryString(FIRCLSFile* file, const char* key, const char* value);
81
void FIRCLSFileWriteStringUnquoted(FIRCLSFile* file, const char* string);
82
#if defined(__OBJC__)
83
void FIRCLSFileWriteHashEntryNSString(FIRCLSFile* file, const char* key, NSString* string);
84
void FIRCLSFileWriteHashEntryNSStringUnlessNilOrEmpty(FIRCLSFile* file,
85
                                                      const char* key,
86
                                                      NSString* string);
87
#endif
88
void FIRCLSFileWriteHashEntryHexEncodedString(FIRCLSFile* file, const char* key, const char* value);
89
void FIRCLSFileWriteHashEntryBoolean(FIRCLSFile* file, const char* key, bool value);
90
 
91
void FIRCLSFileWriteArrayStart(FIRCLSFile* file);
92
void FIRCLSFileWriteArrayEnd(FIRCLSFile* file);
93
void FIRCLSFileWriteArrayEntryUint64(FIRCLSFile* file, uint64_t value);
94
void FIRCLSFileWriteArrayEntryString(FIRCLSFile* file, const char* value);
95
void FIRCLSFileWriteArrayEntryHexEncodedString(FIRCLSFile* file, const char* value);
96
 
97
void FIRCLSFileFDWriteUInt64(int fd, uint64_t number, bool hex);
98
void FIRCLSFileFDWriteInt64(int fd, int64_t number);
99
void FIRCLSFileWriteUInt64(FIRCLSFile* file, uint64_t number, bool hex);
100
void FIRCLSFileWriteInt64(FIRCLSFile* file, int64_t number);
101
 
102
#if defined(__OBJC__) && TARGET_OS_MAC
103
NSArray* FIRCLSFileReadSections(const char* path,
104
                                bool deleteOnFailure,
105
                                NSObject* (^transformer)(id obj));
106
NSString* FIRCLSFileHexEncodeString(const char* string);
107
NSString* FIRCLSFileHexDecodeString(const char* string);
108
#endif
109
 
110
__END_DECLS