Codebase list nvidia-persistenced / dbb8043
Merge tag 'upstream/520.56.06' into main Upstream version 520.56.06 Andreas Beckmann 1 year, 3 months ago
4 changed file(s) with 136 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
594594 }
595595
596596
597
598 /*
599 * nvdircat() - concatenate path elements, inserting a '/' path separator
600 * character between each element.
601 */
602
603 char *nvdircat(const char *str, ...)
604 {
605 const char *s;
606 char *result = nvstrdup("");
607 va_list ap;
608
609 va_start(ap, str);
610
611 for (s = str; s; s = va_arg(ap, char *)) {
612 char *oldresult = result;
613
614 result = nvstrcat(result, s == str ? "" : "/", s, NULL);
615 nvfree(oldresult);
616 }
617
618 va_end(ap);
619
620 collapse_multiple_slashes(result);
621
622 return result;
623 }
624
625
626 /*
627 * dirname(3) workalike that abstracts away implementation-specific behavior:
628 * this function always returns a heap-allocated string that can be passed to
629 * free(3), and never modifies the contents of the original string.
630 */
631 char *nv_dirname(const char *path)
632 {
633 char *last_slash = strrchr(path, '/');
634 if (last_slash) {
635 return nvstrndup(path, last_slash - path);
636 } else {
637 return nvstrdup(".");
638 }
639 }
640
641
642 /*
643 * Simple helper function to write the contents of a NUL-terminated string to
644 * a file. A trailing newline is appended if not already present.
645 * Returns TRUE on success; FALSE if an error occurred.
646 */
647 int nv_string_to_file(const char *destination, const char *data)
648 {
649 char *dname = nv_dirname(destination);
650 int written, newline_success = TRUE;
651 char *error = NULL;
652 int len, ret;
653 FILE *fp;
654
655 ret = nv_mkdir_recursive(dname, 0755, &error, NULL);
656 nvfree(dname);
657 nvfree(error);
658
659 if (!ret) return FALSE;
660
661 fp = fopen(destination, "w");
662 if (!fp) return FALSE;
663
664 len = strlen(data);
665 written = fwrite(data, 1, len, fp);
666 if (data[len-1] != '\n') {
667 if (fwrite("\n", 1, 1, fp) != 1) {
668 newline_success = FALSE;
669 }
670 }
671
672 if (fclose(fp)) return FALSE;
673 if (chmod(destination, 0644)) return FALSE;
674
675 return written == len && newline_success;
676 }
677
678
679
597680 /****************************************************************************/
598681 /* string helper functions */
599682 /****************************************************************************/
719802
720803 }
721804
805
806
807 /*
808 * collapse_multiple_slashes() - remove any/all occurrences of "//" from the
809 * argument string.
810 */
811
812 void collapse_multiple_slashes(char *s)
813 {
814 char *p;
815
816 while ((p = strstr(s, "//")) != NULL) {
817 p++; /* advance to second '/' */
818 while (*p == '/') {
819 unsigned int i, len;
820
821 len = strlen(p);
822 for (i = 0; i < len; i++) p[i] = p[i+1];
823 }
824 }
825 }
7474 char *nv_basename(const char *path);
7575 int nv_mkdir_recursive(const char *path, const mode_t mode,
7676 char **error_str, char **log_str);
77 char *nvdircat(const char *str, ...);
78 char *nv_dirname(const char *path);
79 int nv_string_to_file(const char *, const char *);
7780
7881 char *nv_trim_space(char *string);
7982 char *nv_trim_char(char *string, char trim);
8083 char *nv_trim_char_strict(char *string, char trim);
8184 void remove_trailing_slashes(char *string);
85 void collapse_multiple_slashes(char *s);
8286
8387 int directory_exists(const char *dir);
8488
4242 * through 'boolval'.
4343 */
4444
45 #define NVGETOPT_IS_BOOLEAN 0x01
45 #define NVGETOPT_IS_BOOLEAN 0x0001
4646
4747
4848 /*
5151 * through 'strval'.
5252 */
5353
54 #define NVGETOPT_STRING_ARGUMENT 0x02
54 #define NVGETOPT_STRING_ARGUMENT 0x0002
5555
5656
5757 /*
6060 * argument through 'intval'.
6161 */
6262
63 #define NVGETOPT_INTEGER_ARGUMENT 0x04
63 #define NVGETOPT_INTEGER_ARGUMENT 0x0004
6464
6565
6666 /*
6969 * argument through 'doubleval'.
7070 */
7171
72 #define NVGETOPT_DOUBLE_ARGUMENT 0x08
72 #define NVGETOPT_DOUBLE_ARGUMENT 0x0008
7373
7474
7575 /* helper macro */
8888 * take arguments.
8989 */
9090
91 #define NVGETOPT_ALLOW_DISABLE 0x10
91 #define NVGETOPT_ALLOW_DISABLE 0x0010
9292
9393
9494 /*
9898 * option is returned without an argument.
9999 */
100100
101 #define NVGETOPT_ARGUMENT_IS_OPTIONAL 0x20
101 #define NVGETOPT_ARGUMENT_IS_OPTIONAL 0x0020
102102
103103
104104 /*
109109 * printed.
110110 */
111111
112 #define NVGETOPT_HELP_ALWAYS 0x40
113
112 #define NVGETOPT_HELP_ALWAYS 0x0040
113
114
115 /*
116 * Indicates that an option is deprecated. The description field of the
117 * NVGetoptOption, if set, may be used to store text explaining why the
118 * option is no longer used.
119 */
120
121 #define NVGETOPT_IS_DEPRECATED 0x0080
122
123 /*
124 * These flags indicate that a particular boolean or disableable value is no
125 * longer supported. They can be used together with NVGETOPT_DEPRECATED in
126 * order to differentiate between deprecated boolean values or enable/disable
127 * states that will be ignored, and unsupported boolean values or enable/disable
128 * states that are invalid.
129 */
130
131 #define NVGETOPT_DISABLE_IS_INVALID 0x0100
132 #define NVGETOPT_ENABLE_IS_INVALID 0x0200
114133
115134 typedef struct {
116135 const char *name;
0 NVIDIA_VERSION = 515.86.01
0 NVIDIA_VERSION = 520.56.06
11
22 # This file.
33 VERSION_MK_FILE := $(lastword $(MAKEFILE_LIST))