Skip to content

Commit 0ee6d47

Browse files
committed
Documentation
1 parent 4941015 commit 0ee6d47

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/utils.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,24 +596,34 @@ int xml_pretty_print_in_place(const char *filename, const char *pretty_print_pro
596596
return -1;
597597
}
598598

599+
/**
600+
*
601+
* @param filename /path/to/tox.ini
602+
* @param result path of replacement tox.ini configuration
603+
* @return 0 on success, -1 on error
604+
*/
599605
int fix_tox_conf(const char *filename, char **result) {
600606
struct INIFILE *toxini;
601607
FILE *fptemp;
602608
char *tempfile;
603609
const char *with_posargs = " \\\n {posargs}\n";
604610

611+
// Create new temporary tox configuration file
605612
tempfile = xmkstemp(&fptemp, "w+");
606613
if (!tempfile) {
607614
return -1;
608615
}
609616

617+
// If the result pointer is NULL, allocate enough to store a filesystem path
610618
if (!*result) {
611619
*result = calloc(PATH_MAX, sizeof(**result));
612620
if (!*result) {
621+
guard_free(tempfile);
613622
return -1;
614623
}
615624
}
616625

626+
// Consume the original tox.ini configuration
617627
toxini = ini_open(filename);
618628
if (!toxini) {
619629
if (fptemp) {
@@ -624,6 +634,8 @@ int fix_tox_conf(const char *filename, char **result) {
624634
return -1;
625635
}
626636

637+
// Modify tox configuration
638+
// - Allow passing positional arguments pytest
627639
for (size_t i = 0; i < toxini->section_count; i++) {
628640
struct INISection *section = toxini->section[i];
629641
if (section) {
@@ -650,9 +662,11 @@ int fix_tox_conf(const char *filename, char **result) {
650662
}
651663
}
652664

665+
// Save modified configuration
653666
ini_write(toxini, &fptemp, INI_WRITE_RAW);
654667
fclose(fptemp);
655668

669+
// Store path to modified config
656670
strcpy(*result, tempfile);
657671
guard_free(tempfile);
658672

@@ -661,6 +675,7 @@ int fix_tox_conf(const char *filename, char **result) {
661675
}
662676

663677
static size_t count_blanks(char *s) {
678+
// return the number of leading blanks (tab/space) in a string
664679
size_t blank = 0;
665680
for (size_t i = 0; i < strlen(s); i++) {
666681
if (isblank(s[i])) {
@@ -685,6 +700,14 @@ char *collapse_whitespace(char **s) {
685700
return *s;
686701
}
687702

703+
/**
704+
* Replace sensitive text in strings with ***REDACTED***
705+
* @param to_redact a list of tokens to redact
706+
* @param src to read
707+
* @param dest to write modified string
708+
* @param maxlen maximum length of dest string
709+
* @return 0 on success, -1 on error
710+
*/
688711
int redact_sensitive(const char **to_redact, char *src, char *dest, size_t maxlen) {
689712
char **parts = split(src, " ", 0);
690713
if (!parts) {
@@ -712,6 +735,13 @@ int redact_sensitive(const char **to_redact, char *src, char *dest, size_t maxle
712735
return 0;
713736
}
714737

738+
/**
739+
* Retrieve file names in a directory
740+
* (no metadata, non-recursive)
741+
*
742+
* @param path directory path
743+
* @return StrList structure
744+
*/
715745
struct StrList *listdir(const char *path) {
716746
struct StrList *node;
717747
DIR *dp;

0 commit comments

Comments
 (0)