MCPcopy Create free account
hub / github.com/acl-dev/acl / open_file_log

Function open_file_log

lib_acl/src/stdlib/acl_mylog.c:215–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215static int open_file_log(const char *filename, const char *logpre)
216{
217 const char *myname = "open_file_log";
218#ifdef ACL_WINDOWS
219 int flag = O_RDWR | O_CREAT | O_APPEND | O_BINARY;
220#else
221 int flag = O_RDWR | O_CREAT | O_APPEND;
222#endif
223#ifdef ACL_ANDROID
224 int mode = 0644;
225#else
226 int mode = S_IREAD | S_IWRITE;
227#endif
228 ACL_LOG *log;
229 ACL_ITER iter;
230 ACL_VSTREAM *fp;
231 ACL_FILE_HANDLE fh;
232
233 acl_foreach(iter, __loggers) {
234 log = (ACL_LOG*) iter.data;
235 if (strcmp(log->path, filename) == 0) {
236 acl_msg_warn("%s(%d): log %s has been opened.",
237 myname, __LINE__, filename);
238 return 0;
239 }
240 }
241
242 fh = acl_file_open(filename, flag, mode);
243 if (fh == ACL_FILE_INVALID) {
244 printf("%s(%d): open %s error(%s)", myname, __LINE__,
245 filename, acl_last_serror());
246 return -1;
247 }
248
249 fp = private_vstream_fhopen(fh, O_RDWR);
250
251#if 0
252 acl_vstream_set_path(fp, filename);
253#else
254 fp->path = strdup(filename);
255#endif
256
257#ifdef ACL_UNIX
258 if (__log_close_onexec) {
259 acl_close_on_exec(fh, ACL_CLOSE_ON_EXEC);
260 }
261#endif
262
263 log = (ACL_LOG*) calloc(1, sizeof(ACL_LOG));
264 acl_assert(log);
265 log->last_open = time(NULL);
266 log->fp = fp;
267 log->path = strdup(filename);
268 log->type = ACL_LOG_T_FILE;
269 log->lock = (acl_pthread_mutex_t*)
270 calloc(1, sizeof(acl_pthread_mutex_t));
271 init_log_mutex(log->lock);
272 if (logpre && *logpre) {

Callers 1

open_logFunction · 0.85

Calls 10

acl_msg_warnFunction · 0.85
acl_file_openFunction · 0.85
acl_last_serrorFunction · 0.85
private_vstream_fhopenFunction · 0.85
acl_vstream_set_pathFunction · 0.85
acl_close_on_execFunction · 0.85
callocFunction · 0.85
init_log_mutexFunction · 0.85
private_fifo_pushFunction · 0.85
acl_foreachFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…