两个文件即可。当然这只是编译,想直接将文件放入到image中还是需要另外的设置的。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <errno.h>
#define LOG_TAG "FILE_TEST"
#include "cutils/log.h"
static int write_file(const char *path, const char *value)
{
int fd, ret, len;
int open_flag = O_RDWR;
int open_mode = 0;
ret = access(path, 0);
if(ret != 0){
LOGE("access:%s ret != 0\n", path);
open_flag = O_RDWR;
}else{
LOGE("access:%s ret == 0\n", path);
open_flag = O_CREAT;
open_mode = S_IWUSR;
}
fd = creat(path, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) {
LOGE("creat: can't creat file:%s\n", path);
return -errno;
}
close(fd);
fd = open(path, O_WRONLY);
if (fd < 0) {
LOGE("write_file: can't open file:%s\n", path);
return -errno;
}
len = strlen(value);
do {
ret = write(fd, value, len);
} while (ret < 0 && errno == EINTR);
close(fd);
if (ret < 0) {
LOGE("write file failed:%s,%s\n",path, value);
return -errno;
}
return 0;
}
static void usage(char *argv[])
{
fprintf(stderr,"Usage:\n");
fprintf(stderr,"%s wrmmod\n", argv[0]);
fprintf(stderr,"%s wtx -n nmode -c ch -r rate -p pwr\n", argv[0]);
fprintf(stderr,"%s wtstop\n", argv[0]);
fprintf(stderr,"%s wrx -c ch -r rate -n nmode\n", argv[0]);
fprintf(stderr,"%s wrc -n pktnum\n", argv[0]);
fprintf(stderr,"%s bt -f freq -t pkttype\n", argv[0]);
fprintf(stderr,"Don't ommit any options and don't change the sequence of the options and params\n");
}
int main(int argc, char *argv[])
{
if(argc != 2){
usage(argv);
return -1;
}
LOGE("--wl main---");
char pathname[] = "/system/etc/2.txt";
char string[] = "this is in main function wifi_test\n";
write_file(pathname, string);
return 0;
}
android.mk文件内容:
# Copyright (C) 2011 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.
ifeq ($(TARGET_BOARD_PLATFORM),ns115)
ifeq ($(TARGET_PRODUCT_NAME),HDMI_STICKER)
ifeq ($(CAMERA_DEVICE_TYPE),WALLE)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE := wifi_test
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES += wifi_test.c
LOCAL_SHARED_LIBRARIES := \
liblog
LOCAL_C_INCLUDES :=
include $(BUILD_EXECUTABLE)
endif
endif
endif