android4.0.3在hardware文件下添加一个可以编译为执行文件的方法

两个文件即可。当然这只是编译,想直接将文件放入到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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值