TRY_Q("fopen", out);
if (!out) { perror("FAILED: fopen"); return 1; }
main(int argc, char **argv){    XPTHeader *header;    XPTInterfaceDescriptor *id;    XPTState *state;    XPTCursor curs, *cursor = &curs;    char *data;    FILE *out;    uint32 len, header_sz;    PRBool ok;        if (argc != 2) {	fprintf(stderr, "Usage: %s <filename.xpt>\n"		"       Creates a simple typelib file.\n", argv[0]);		return 1;    }    /* construct a header */    header = XPT_NewHeader(1);    TRY("NewHeader", header);    header->annotations = XPT_NewAnnotation(PR_TRUE, PR_TRUE, NULL, NULL);    TRY("NewAnnotation", header->annotations);    header_sz = XPT_SizeOfHeaderBlock(header);    id = XPT_NewInterfaceDescriptor(0, 0, 0);    TRY("NewInterfaceDescriptor", id);        ok = XPT_FillInterfaceDirectoryEntry(header->interface_directory, &iid,					 "nsIFoo", "nsIBar", id);    TRY("FillInterfaceDirectoryEntry", ok);    /* serialize it */    state = XPT_NewXDRState(XPT_ENCODE, NULL, 0);    TRY("NewState (ENCODE)", state);        XPT_SetDataOffset(state, header_sz);        ok = XPT_MakeCursor(state, XPT_HEADER, header_sz, cursor);    TRY("MakeCursor", ok);    ok = XPT_DoHeader(cursor, &header);    TRY("DoHeader", ok);    out = fopen(argv[1], "w");    TRY_Q("fopen", out);        XPT_GetXDRData(state, XPT_HEADER, &data, &len);    fwrite(data, len, 1, out);    XPT_GetXDRData(state, XPT_DATA, &data, &len);    fwrite(data, len, 1, out);    fclose(out);    XPT_DestroyXDRState(state);    /* XXX DestroyHeader */    return 0;}