2 * upgrade-apply-deltafs
4 * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <sys/types.h>
29 #define DEF_MAX_LOG_SIZE (2*1024*1024)
30 #define MAX_FILE_PATH 512
34 long backup_offset = 0;
35 long max_logfile_size = DEF_MAX_LOG_SIZE;
37 /*-----------------------------------------------------------------------------
39 ----------------------------------------------------------------------------*/
40 int log_printf(FILE* log_fp, char* format_str, ...)
48 va_start(list, format_str);
49 vsnprintf(log_str, sizeof(log_str), format_str, list);
52 len = strlen(log_str);
53 next_offset = curr_offset + len;
55 if (next_offset <= max_logfile_size) {
56 if (fprintf(log_fp, "%s", log_str) < 0) {
60 curr_offset = next_offset;
61 if (curr_offset == max_logfile_size) {
66 backup_offset = max_logfile_size - curr_offset;
67 backup_ch = log_str[backup_offset];
68 log_str[backup_offset] = 0x00;
69 if (fprintf(log_fp, "%s", log_str) < 0) {
74 log_str[backup_offset] = backup_ch;
75 if (fprintf(log_fp, "%s", log_str+backup_offset) < 0) {
79 curr_offset = next_offset - max_logfile_size;