+ if (ptr == NULL)
+ return 0;
+
+ result = fclose (ptr);
+ if (result == EOF)
+ error (2, errno, _("cannot close file"));
+
+ return result;
+}
+
+/*--------------------------------------------------.
+| Save the content of the obstack OBS in FILENAME. |
+`--------------------------------------------------*/
+
+static void
+obstack_save (struct obstack *obs, const char *filename)
+{
+ FILE *out = xfopen (filename, "w");
+ size_t size = obstack_object_size (obs);
+ fwrite (obstack_finish (obs), 1, size, out);
+ xfclose (out);
+}
+
+/*---------------------------------------------------------------------.
+| Output double inclusion protection macros and saves defines_obstack |
+`---------------------------------------------------------------------*/
+
+static void
+defines_obstack_save (const char *filename)
+{
+ FILE *out = xfopen (filename, "w");
+ size_t size = obstack_object_size (&defines_obstack);
+ char *macro_name = compute_header_macro ();
+
+ fprintf (out, "#ifndef %s\n", macro_name);
+ fprintf (out, "# define %s\n\n", macro_name);
+ fwrite (obstack_finish (&defines_obstack), 1, size, out);
+ fprintf (out, "\n#endif /* not %s */\n", macro_name);
+
+ free (macro_name);
+ xfclose (out);
+}
+
+/*------------------------------------------------------------------.
+| Return the path to the skeleton which locaction might be given in |
+| ENVVAR, otherwise return SKELETON_NAME. |
+`------------------------------------------------------------------*/
+
+const char *
+skeleton_find (const char *envvar, const char *skeleton_name)
+{
+ const char *res = getenv (envvar);