فهرست منبع

Add maxlen parameter to libmegapixels_find_config

Martijn Braam 6 ماه پیش
والد
کامیت
b71aec6e18
5فایلهای تغییر یافته به همراه11 افزوده شده و 9 حذف شده
  1. 3 2
      include/libmegapixels.h
  2. 5 4
      src/findconfig.c
  3. 1 1
      util/findconfig.c
  4. 1 1
      util/getframe.c
  5. 1 1
      util/sensorprofile.c

+ 3 - 2
include/libmegapixels.h

@@ -3,15 +3,16 @@
 
 #include <stdint.h>
 #include <linux/videodev2.h>
+#include <stdio.h>
 
 #define EXPORT __attribute__((__visibility__("default")))
 
 
 EXPORT int
-libmegapixels_find_config(char *configfile);
+libmegapixels_find_config(ssize_t maxlen, char *configfile);
 
 EXPORT int
-libmegapixels_find_config_verbose(char *configfile, int print);
+libmegapixels_find_config_verbose(ssize_t maxlen, char *configfile, int print);
 
 #define LIBMEGAPIXELS_CMD_LINK 1
 #define LIBMEGAPIXELS_CMD_MODE 2

+ 5 - 4
src/findconfig.c

@@ -14,6 +14,7 @@ static int
 find_device_by_model(ssize_t maxlen, char *conffile, char *model, int print)
 {
 	// Check config/%model.conf in the current working directory
+
 	snprintf(conffile, maxlen, "config/%s.conf", model);
 	if (print) {
 		printf("- %s\n", conffile);
@@ -46,7 +47,7 @@ find_device_by_model(ssize_t maxlen, char *conffile, char *model, int print)
 }
 
 int
-libmegapixels_find_config_verbose(char *configfile, int print)
+libmegapixels_find_config_verbose(ssize_t maxlen, char *configfile, int print)
 {
 	char model[512];
 	FILE *fp;
@@ -63,7 +64,7 @@ libmegapixels_find_config_verbose(char *configfile, int print)
 		}
 		*(modelptr++) = (char) c;
 		if (c == 0) {
-			if (find_device_by_model(sizeof(model), configfile, model, print)) {
+			if (find_device_by_model(maxlen, configfile, model, print)) {
 				return 1;
 			}
 			modelptr = model;
@@ -72,7 +73,7 @@ libmegapixels_find_config_verbose(char *configfile, int print)
 }
 
 int
-libmegapixels_find_config(char *configfile)
+libmegapixels_find_config(ssize_t maxlen, char *configfile)
 {
-	return libmegapixels_find_config_verbose(configfile, 0);
+	return libmegapixels_find_config_verbose(maxlen, configfile, 0);
 }

+ 1 - 1
util/findconfig.c

@@ -35,7 +35,7 @@ main(int argc, char *argv[])
 				return 1;
 		}
 	}
-	ret = libmegapixels_find_config_verbose(configpath, verbose);
+	ret = libmegapixels_find_config_verbose(PATH_MAX, configpath, verbose);
 	libmegapixels_devconfig *config = {0};
 	libmegapixels_init(&config);
 

+ 1 - 1
util/getframe.c

@@ -106,7 +106,7 @@ main(int argc, char *argv[])
 
 
 	char configpath[PATH_MAX];
-	int ret = libmegapixels_find_config(configpath);
+	int ret = libmegapixels_find_config(PATH_MAX, configpath);
 	libmegapixels_devconfig *config = {0};
 	libmegapixels_init(&config);
 	if (verbose) {

+ 1 - 1
util/sensorprofile.c

@@ -227,7 +227,7 @@ main(int argc, char *argv[])
 
 
 	char configpath[PATH_MAX];
-	int ret = libmegapixels_find_config(configpath);
+	int ret = libmegapixels_find_config(PATH_MAX, configpath);
 	libmegapixels_devconfig *config = {0};
 	libmegapixels_init(&config);