blob: 9ca07d9ce2756df5a5a8403e0aca75f8bda6b8dd [file] [log] [blame]
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BUILD_TOOLS_APPLYPATCH_UTILS_H
#define _BUILD_TOOLS_APPLYPATCH_UTILS_H
#include <sys/types.h>
#include <stdio.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <err.h>
#include <fcntl.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#define free_ptr(ptr) if(ptr!=NULL)free(ptr);ptr=NULL;
#define close_fp(fp) if(fp!=NULL)fclose(fp);fp=NULL;
#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
#define GOERR_IF_FAIL(x) do{if((x) < 0) goto out_error;}while(0)
#define GOERR_IF_NOK(x) do{if((x) != 0) goto out_error;}while(0)
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned char u_char;
typedef unsigned char uint8_t;
#define MIN(x,y) (((x)<(y)) ? (x) : (y))
#define MAX(x,y) (((x)>(y)) ? (x) : (y))
#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
#define log(fmt, args...) do {printf("[%s:%d]"fmt"\n", __FUNCTION__, __LINE__, ##args);}while(0)
#define LOGD(fmt, args...) do {printf("[%s:%d]"fmt"\n", __FUNCTION__, __LINE__, ##args);}while(0)
#define LOGE(fmt, args...) do {printf("[%s:%d]"fmt"\n", __FUNCTION__, __LINE__, ##args);}while(0)
#define GOERR_IF_FAIL(x) do{if((x) < 0) goto out_error;}while(0)
unsigned char * readfile(const char *dir, const char *name, size_t *len);
int write_file(FILE* fp, const void *buf, int count);
void dump_data(const u_char* data, int n);
uint32_t little_endian_offin(u_char *buf);
void little_endian_offout(uint32_t x, u_char *buf);
FILE* create_new_file(const char* name);
char *dir_name(char * path);
int write_file_by_path(const char*path, const char*value, int size);
int read_file_by_path(const char*path, char*buf, int sz);
// Read and write little-endian values of various sizes.
void Write4(int value, FILE* f);
void Write8(long long value, FILE* f);
int Read2(void* p);
int Read4(void* p);
long long Read8(void* p);
#endif // _BUILD_TOOLS_APPLYPATCH_UTILS_H