66 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
# 1. 客制化目录
 | 
						||
 | 
						||
## 1.1. 概述
 | 
						||
   客制化目录,依赖整个项目源码(含各层目录),继承并重载接口实现客制化功能,用于管理定制化版本 / Debug版本 / 生产版本等,使特殊功能代码与公版代码解耦合,保持公版版本功能稳定性和一致性。
 | 
						||
 | 
						||
## 1.2. Debug版本
 | 
						||
 | 
						||
### 1.2.1. Debug版本概述
 | 
						||
   Debug版本用于满足测试需求,例如:开启log / 特殊的功能。
 | 
						||
 | 
						||
### 1.2.2. 生产测试版本
 | 
						||
   生产时使用的验证产品功能的版本。
 | 
						||
 | 
						||
### 1.2.3. 其它定制版本
 | 
						||
 | 
						||
   基于公版,继承派生出来的特殊功能的商业化版本。
 | 
						||
 | 
						||
```
 | 
						||
#include <stdio.h>
 | 
						||
#include <stdlib.h>
 | 
						||
#include <string.h>
 | 
						||
 | 
						||
int is_mounted(const char *dirpath) {
 | 
						||
    FILE *fp;
 | 
						||
    char line[1024];
 | 
						||
    char mount_point[1024];
 | 
						||
 | 
						||
    // 尝试打开 /proc/mounts 文件
 | 
						||
    fp = fopen("/proc/mounts", "r");
 | 
						||
    if (fp == NULL) {
 | 
						||
        perror("Error opening /proc/mounts");
 | 
						||
        return -1;
 | 
						||
    }
 | 
						||
 | 
						||
    // 逐行读取并查找挂载点
 | 
						||
    while (fgets(line, sizeof(line), fp) != NULL) {
 | 
						||
        if (sscanf(line, "%*s %1023s %*s %*s %*d %*d\n", mount_point) == 1) {
 | 
						||
            // 检查当前行中的挂载点是否与所查找的目录匹配
 | 
						||
            if (strcmp(dirpath, mount_point) == 0) {
 | 
						||
                fclose(fp);
 | 
						||
                return 1; // 已挂载
 | 
						||
            }
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
    fclose(fp);
 | 
						||
    return 0; // 未挂载
 | 
						||
}
 | 
						||
 | 
						||
int main(int argc, char *argv[]) {
 | 
						||
    if (argc != 2) {
 | 
						||
        fprintf(stderr, "Usage: %s <directory>\n", argv[0]);
 | 
						||
        return 1;
 | 
						||
    }
 | 
						||
 | 
						||
    const char *dirpath = argv[1];
 | 
						||
 | 
						||
    if (is_mounted(dirpath)) {
 | 
						||
        printf("Directory '%s' is mounted.\n", dirpath);
 | 
						||
    } else {
 | 
						||
        printf("Directory '%s' is not mounted.\n", dirpath);
 | 
						||
    }
 | 
						||
 | 
						||
    return 0;
 | 
						||
}
 | 
						||
``` |