Follow-up Comment #2, bug #63219 (project make): This is the example from the manual extended with a close function
++++ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <gnumake.h> int plugin_is_GPL_compatible; struct file { struct file *next; char *name; }; static struct file *files = NULL; static char * gen_tmpfile (const char *nm, int argc, char **argv) { int fd; /* Compute the size of the filename and allocate space for it. */ int len = strlen (argv[0]) + 6 + 1; char *buf = gmk_alloc (len); strcpy (buf, argv[0]); strcat (buf, "XXXXXX"); fd = mkstemp(buf); if (fd >= 0) { struct file *new = (struct file *) malloc (sizeof *new); new->name = strdup (buf); new->next = files; files = new; /* Don't leak the file descriptor. */ close (fd); return buf; } /* Failure. */ fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno)); gmk_free (buf); return NULL; } int mk_temp_gmk_setup (const gmk_floc *floc) { printf ("mk_temp plugin loaded from %s:%lu\n", floc->filenm, floc->lineno); /* Register the function with make name "mk-temp". */ gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1); return 1; } void mk_temp_gmk_close () { while (files) { struct file *f = files; printf ("unlinking %s\n", f->name); unlink (f->name); free (f->name); files = f->next; free (f); } files = NULL; printf ("mk_temp plugin unloaded\n"); } ---- Now when you run make you’ll see something like: ++++ $ make mk_temp plugin loaded from makefile:1 Temporary file tmpfile.O7vuwn unlinking tmpfile.O7vuwn mk_temp plugin unloaded cc -shared -fPIC -o mk_temp.so mk_temp.c mk_temp plugin loaded from makefile:1 Temporary file tmpfile.lpgecm Temporary file tmpfile.sIdBvo unlinking tmpfile.sIdBvo unlinking tmpfile.lpgecm mk_temp plugin unloaded ---- _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?63219> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/