fp = fopen (tmp_nam, "wb");
fd = open(tmp_nam, O_WRONLY|O_CREAT|O_EXCL, 0600); if (fd != -1) fp = fdopen(fd, "wb");
static int write_auth_file (tmp_nam)    char *tmp_nam;{    FILE *fp;    AuthList *list;    /*     * xdm and auth spec assumes auth file is 12 or fewer characters     */    strcpy (tmp_nam, xauth_filename);    strcat (tmp_nam, "-n");		/* for new */    (void) unlink (tmp_nam);    fp = fopen (tmp_nam, "wb");		/* umask is still set to 0077 */    if (!fp) {	fprintf (stderr, "%s:  unable to open tmp file \"%s\"\n",		 ProgramName, tmp_nam);	return -1;    }     /*     * Write MIT-MAGIC-COOKIE-1 first, because R4 Xlib knows     * only that and uses the first authorization it finds.     */    for (list = xauth_head; list; list = list->next) {	if (list->auth->name_length == 18	    && strncmp(list->auth->name, "MIT-MAGIC-COOKIE-1", 18) == 0)	{	    XauWriteAuth (fp, list->auth);	}    }    for (list = xauth_head; list; list = list->next) {	if (list->auth->name_length != 18	    || strncmp(list->auth->name, "MIT-MAGIC-COOKIE-1", 18) != 0)	{	    XauWriteAuth (fp, list->auth);	}    }    (void) fclose (fp);    return 0;}