/* compile, link, and load the file */ static void process_file(struct astr *sfilename) { char *dsofile; struct dso_entry *entry; int r; fprintf(stderr, PROCTEXT("Compiling %s...\n"), astr_cstr(sfilename)); dsofile = compile(sfilename); if(dsofile == NULL) { fprintf(stderr, ERRORTEXT("Compilation failed.\n")); return; } fprintf(stderr, SUCCESSTEXT("Compilation succeeded.\n")); fprintf(stderr, PROCTEXT("Loading %s...\n"), dsofile); entry = load(dsofile); if(entry == NULL) { fprintf(stderr, ERRORTEXT("Load failed.\n")); r = unlink(dsofile); if(r != 0) { fprintf(stderr, ERRORTEXT("Failed to unlink %s") ": %s\n", dsofile, strerror(errno)); } return; } fprintf(stderr, SUCCESSTEXT("Load succeeded.\n")); run(entry); }
HRESULT hrOEMDevMode(DWORD dwMode, POEMDMPARAM pOemDMParam) { POEMDEV pOEMDevIn; POEMDEV pOEMDevOut; // Verify parameters. if( (NULL == pOemDMParam) || ( (OEMDM_SIZE != dwMode) && (OEMDM_DEFAULT != dwMode) && (OEMDM_CONVERT != dwMode) && (OEMDM_MERGE != dwMode) ) ) { ERR(ERRORTEXT("DevMode() ERROR_INVALID_PARAMETER.\r\n")); VERBOSE(DLLTEXT("\tdwMode = %d, pOemDMParam = %#lx.\r\n"), dwMode, pOemDMParam); SetLastError(ERROR_INVALID_PARAMETER); return E_FAIL; } // Cast generic (i.e. PVOID) to OEM private devomode pointer type. pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn; pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut; switch(dwMode) { case OEMDM_SIZE: pOemDMParam->cbBufSize = sizeof(OEMDEV); break; case OEMDM_DEFAULT: pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; pOEMDevOut->dwDriverData = 0; pOEMDevOut->dwAdvancedData = 0; VERBOSE(DLLTEXT("pOEMDevOut after setting default values:\r\n")); Dump(pOEMDevOut); break; case OEMDM_CONVERT: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut, pOemDMParam->cbBufSize); break; case OEMDM_MERGE: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut, pOemDMParam->cbBufSize); MakeOEMDevmodeValid(pOEMDevOut); break; } Dump(pOemDMParam); return S_OK; }
BOOL ConvertOEMDevmode(PCOEMDEV pOEMDevIn, POEMDEV pOEMDevOut, DWORD dwSize) { if( (NULL == pOEMDevIn) || (NULL == pOEMDevOut) || (dwSize < sizeof(OEMDEV)) ) { ERR(ERRORTEXT("ConvertOEMDevmode() invalid parameters.\r\n")); return FALSE; } // Check OEM Signature, if it doesn't match ours, // then just assume DMIn is bad and use defaults. if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature) { VERBOSE(DLLTEXT("Converting private OEM Devmode.\r\n")); VERBOSE(DLLTEXT("pOEMDevIn:\r\n")); Dump(pOEMDevIn); // Set the devmode defaults so that anything the isn't copied over will // be set to the default value. pOEMDevOut->dwDriverData = 0; pOEMDevOut->dwAdvancedData = 0; // Copy the old structure in to the new using which ever size is the smaller. // Devmode maybe from newer Devmode (not likely since there is only one), or // Devmode maybe a newer Devmode, in which case it maybe larger, // but the first part of the structure should be the same. // DESIGN ASSUMPTION: the private DEVMODE structure only gets added to; // the fields that are in the DEVMODE never change only new fields get added to the end. memcpy(pOEMDevOut, pOEMDevIn, __min(dwSize, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize))); // Re-fill in the size and version fields to indicated // that the DEVMODE is the current private DEVMODE version. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; } else { WARNING(DLLTEXT("Unknown DEVMODE signature, pOEMDMIn ignored.\r\n")); // Don't know what the input DEVMODE is, so just use defaults. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; pOEMDevOut->dwDriverData = 0; pOEMDevOut->dwAdvancedData = 0; } return TRUE; }
// Create a list of pointers to the strings // in a multi-sz. HRESULT MakeStrPtrList(HANDLE hHeap, PCSTR pmszMultiSz, PCSTR **pppszList, PWORD pwCount) { PCSTR *ppszList = NULL; HRESULT hrResult = S_OK; // Validate parameters if( (NULL == hHeap) || (NULL == pmszMultiSz) || (NULL == pppszList) || (NULL == pwCount) ) { return E_INVALIDARG; } // Get the count of strings in the multi-sz. *pwCount = mstrcount(pmszMultiSz); if(0 == *pwCount) { WARNING(DLLTEXT("MakeStrPtrList() pmszMultiSz contains no strings.\r\n")); goto Exit; } // Allocate pointer list. *pppszList = (PCSTR *) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, (*pwCount) * sizeof(PCSTR)); if(NULL == *pppszList) { ERR(ERRORTEXT("MakeStrPtrList() failed to allote array of PCSTR.\r\n")); hrResult = E_OUTOFMEMORY; goto Exit; } ppszList = *pppszList; // Walk multi-sz mapping string pointers. for(WORD wIndex = 0; wIndex < *pwCount; ++wIndex) { ppszList[wIndex] = pmszMultiSz; pmszMultiSz += lstrlenA(pmszMultiSz) + 1; } Exit: return hrResult; }
/* set up the appropriate watch on the directory indicated by sfilename */ static int setup_inotify_watch(int notify_fd, struct astr *sfilename) { char dirbuf[astr_len(sfilename) + 1]; char *dir; int dwatch; strcpy(dirbuf, astr_cstr(sfilename)); dir = dirname(dirbuf); dwatch = inotify_add_watch(notify_fd, dir, IN_CLOSE_WRITE|IN_MOVED_TO); if(dwatch <= 0) { fprintf(stderr, ERRORTEXT("Fatal: failed to add inotify watch for %s") ": %s\n", dir, strerror(errno)); exit(EXIT_FAILURE); } return dwatch; }
void Dump(PCOEMDEV pOEMDevmode) { if( (NULL != pOEMDevmode) && (pOEMDevmode->dmOEMExtra.dwSize >= sizeof(OEMDEV)) && (OEM_SIGNATURE == pOEMDevmode->dmOEMExtra.dwSignature) ) { VERBOSE(TEXT("\tdmOEMExtra.dwSize = %d\r\n"), pOEMDevmode->dmOEMExtra.dwSize); VERBOSE(TEXT("\tdmOEMExtra.dwSignature = %#x\r\n"), pOEMDevmode->dmOEMExtra.dwSignature); VERBOSE(TEXT("\tdmOEMExtra.dwVersion = %#x\r\n"), pOEMDevmode->dmOEMExtra.dwVersion); VERBOSE(TEXT("\tdwDriverData = %#x\r\n"), pOEMDevmode->dwDriverData); VERBOSE(TEXT("\tdwAdvancedData = %#x\r\n"), pOEMDevmode->dwAdvancedData); } else { ERR(ERRORTEXT("Dump(POEMDEV) unknown private OEM DEVMODE.\r\n")); } }
void watch_file() { int r; int notify_fd; int dwatch; struct astr *sfilename; char *file; uint8_t inotify_buf[sizeof(struct inotify_event) + NAME_MAX + 1]; struct inotify_event *event; size_t i; ssize_t len; /* initialize the inotify system */ notify_fd = inotify_init(); if(notify_fd < 0) { perror(ERRORTEXT("Fatal: failed to initialize " "inotify system")); exit(EXIT_FAILURE); } setup_watch: /* set up the inotify watch and associated variables */ sfilename = (struct astr *) arcp_load(&livec_opts.filename); if(sfilename == NULL) { fprintf(stderr, ERRORTEXT("Fatal: no filename defined\n")); exit(EXIT_FAILURE); } file = simple_basename(astr_cstr(sfilename)); dwatch = setup_inotify_watch(notify_fd, sfilename); /* process the file */ process_file(sfilename); /* main watch loop */ for(;;) { if(sfilename != (struct astr *) arcp_load_phantom(&livec_opts.filename)) { /* the filename option has changed; remove the watch * and restart */ arcp_release(sfilename); r = inotify_rm_watch(notify_fd, dwatch); if(r != 0) { perror(ERRORTEXT("Failed to clean" " up old watch")); } goto setup_watch; } /* block until there's at least one event to be notified * about */ len = read(notify_fd, inotify_buf, sizeof(struct inotify_event) + NAME_MAX + 1); if(len <= 0) { perror(ERRORTEXT("read() of inotify event failed")); continue; } /* read through all events */ for(i = 0; i <= len - sizeof(struct inotify_event);) { event = (struct inotify_event *) &inotify_buf[i]; i += sizeof(struct inotify_event) + event->len; if(event->wd != dwatch) { /* FIXME: why wouldn't this be the same? */ continue; } if((event->mask & (IN_CLOSE_WRITE|IN_MOVED_TO)) && (strcmp(event->name, file) == 0)) { /* FIXME: do we need the event mask test * here? */ /* the (directory) event was about the file * we're interested in */ process_file(sfilename); break; } } } }
_Out_ PDWORD pcbNeeded ) { // Validate parameters. if( ( (OEMGI_GETSIGNATURE != dwInfo) && (OEMGI_GETINTERFACEVERSION != dwInfo) && (OEMGI_GETVERSION != dwInfo) ) || (NULL == pcbNeeded) ) { VERBOSE(ERRORTEXT("TTYGetInfo() ERROR_INVALID_PARAMETER.\r\n")); // Did not write any bytes. if(NULL != pcbNeeded) *pcbNeeded = 0; return FALSE; } // Need/wrote 4 bytes. *pcbNeeded = 4; // Validate buffer size. Minimum size is four bytes. if( (NULL == pBuffer) || (4 > cbSize)
HRESULT hrOEMDevMode( DWORD dwMode, POEMDMPARAM pOemDMParam ) /*++ Routine Description: Implementation of IPrintOemUni::DevMode. hrOEMDevMode is called by IPrintOemUni::DevMode which is defined in intrface.cpp. The IPrintOemUni::DevMode method, provided by rendering plug-ins for Unidrv, performs operations on private DEVMODE members. Please refer to DDK documentation for more details. Arguments: dwMode - caller-supplied constant. Refer to the docs for more information. pOemDMParam - pointer to an OEMDMPARAM structure. Return Value: S_OK The operation succeeded. E_FAIL The operation failed. --*/ { POEMDEV pOEMDevIn; POEMDEV pOEMDevOut; VERBOSE(L"hrOEMDevMode entry."); // Verify parameters. if( (NULL == pOemDMParam) || ( (OEMDM_SIZE != dwMode) && (OEMDM_DEFAULT != dwMode) && (OEMDM_CONVERT != dwMode) && (OEMDM_MERGE != dwMode) )) { ERR(ERRORTEXT("DevMode() ERROR_INVALID_PARAMETER.\r\n")); ERR(DLLTEXT("\tdwMode = %d, pOemDMParam = %#lx.\r\n"), dwMode, pOemDMParam); SetLastError(ERROR_INVALID_PARAMETER); return E_FAIL; } // Cast generic (i.e. PVOID) to OEM private devmode pointer type. pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn; pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut; switch(dwMode) { case OEMDM_SIZE: pOemDMParam->cbBufSize = sizeof(OEMDEV); break; case OEMDM_DEFAULT: pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; pOEMDevOut->dwDriverData = 0; break; case OEMDM_CONVERT: bConvertOEMDevmode(pOEMDevIn, pOEMDevOut); break; case OEMDM_MERGE: bConvertOEMDevmode(pOEMDevIn, pOEMDevOut); bMakeOEMDevmodeValid(pOEMDevOut); break; } DBG_OEMDMPARAM(DBG_VERBOSE, L"pOemDMParam", pOemDMParam); return S_OK; }
BOOL bConvertOEMDevmode( PCOEMDEV pOEMDevIn, POEMDEV pOEMDevOut ) /*++ Routine Description: Converts private DEVMODE members to the current version. Arguments: pOEMDevIn - pointer to OEM private devmode pOEMDevOut - pointer to OEM private devmode Return Value: TRUE if successful, FALSE if there is an error --*/ { VERBOSE(L"bConvertOEMDevmode entry."); if( (NULL == pOEMDevIn) || (NULL == pOEMDevOut) ) { ERR(ERRORTEXT("ConvertOEMDevmode() invalid parameters.\r\n")); return FALSE; } // Check OEM Signature, if it doesn't match ours, // then just assume DMIn is bad and use defaults. if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature) { VERBOSE(TEXT("Converting private OEM Devmode.\r\n")); // Set the devmode defaults so that anything the isn't copied over will // be set to the default value. pOEMDevOut->dwDriverData = 0; // Copy the old structure in to the new using which ever size is the smaller. // Devmode maybe from newer Devmode (not likely since there is only one), or // Devmode maybe a newer Devmode, in which case it maybe larger, // but the first part of the structure should be the same. // DESIGN ASSUMPTION: the private DEVMODE structure only gets added to; // the fields that are in the DEVMODE never change only new fields get added to the end. memcpy(pOEMDevOut, pOEMDevIn, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize)); // Re-fill in the size and version fields to indicated // that the DEVMODE is the current private DEVMODE version. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; } else { VERBOSE(TEXT("Unknown DEVMODE signature, pOEMDMIn ignored.\r\n")); // Don't know what the input DEVMODE is, so just use defaults. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; pOEMDevOut->dwDriverData = 0; } return TRUE; }
//+--------------------------------------------------------------------------- // // Member: // ::hrOEMDevMode // // Synopsis: // Performs operation on UI Plugins Private DevMode Members. // Called via IOemUI::DevMode // // Returns: // S_OK or E_FAIL. For more detailed failure info, // check GetLastError // // Last error: // ERROR_INVALID_PARAMETER // // //---------------------------------------------------------------------------- HRESULT hrOEMDevMode( DWORD dwMode, // Indicates which operation should be performed _Inout_ POEMDMPARAM pOemDMParam // contains various data structures needed by this // routine. The usage of this struct is determined by // the dwMode flag. ) { VERBOSE(DLLTEXT("hrOEMDevMode entry.")); HRESULT hr = S_OK; // Return value. // // Verify parameters. // if ((NULL == pOemDMParam) || ((OEMDM_SIZE != dwMode) && (OEMDM_DEFAULT != dwMode) && (OEMDM_CONVERT != dwMode) && (OEMDM_MERGE != dwMode))) { ERR(ERRORTEXT("DevMode() ERROR_INVALID_PARAMETER.\r\n")); ERR(DLLTEXT("\tdwMode = %d, pOemDMParam = %#lx.\r\n"), dwMode, pOemDMParam); SetLastError(ERROR_INVALID_PARAMETER); hr = E_FAIL; } else { POEMDEV pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn;; // Pointer to the supplied OEM devmode data, if applicable // based on dwMode. POEMDEV pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut;; // Pointer to the DEVMODE data that this routine is // expected to configure, if applicable based on dwMode. switch (dwMode) { // // The Method should return the size of the memory allocation // needed to store the UI plugin Private DEVMODE. // case OEMDM_SIZE: pOemDMParam->cbBufSize = sizeof(OEMDEV); break; // //Should fill the Private DEVMODE with the default values. // case OEMDM_DEFAULT: // //OEM_DMEXTRAHEADER Members // pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; break; // // The method should convert private DEVMODE members to // the current version, if necessary. // case OEMDM_CONVERT: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut); break; // // The method should validate the information contained in private // DEVMODE members and merge validated values into a private // DEVMODE structure containing default values // case OEMDM_MERGE: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut); MakeOEMDevmodeValid(pOEMDevOut); break; } } return hr; }
//+--------------------------------------------------------------------------- // // Member: // ::ConvertOEMDevmode // // Synopsis: // confirm that the private DEVMODE being passed in is data that // this driver recognizes, read the settings from the input // OEM DEVMODE data, and write them to pOEMDevOut. // // Returns: // True unless the routine was called with null pointers // // //---------------------------------------------------------------------------- BOOL ConvertOEMDevmode( _In_ PCOEMDEV pOEMDevIn, // Caller supplied DEVMODE that we are attempting to read _Inout_ POEMDEV pOEMDevOut // OEM private DEVMODE configured by this routine based on the settings // in pOEMDevIn ) { VERBOSE(DLLTEXT("ConvertOEMDevmode entry.")); if ((NULL == pOEMDevIn) || (NULL == pOEMDevOut)) { ERR(ERRORTEXT("ConvertOEMDevmode() invalid parameters.\r\n")); return FALSE; } // // Check OEM Signature, if it doesn't match ours, // then just assume DMIn is bad and use defaults. // if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature) { VERBOSE(DLLTEXT("Converting private OEM Devmode.\r\n")); // // Copy the old structure in to the new using which ever size is the // smaller. Devmode maybe from newer Devmode (not likely since there // is only one), or Devmode maybe a newer Devmode, in which case it // maybe larger, but the first part of the structure should be the same. // // DESIGN ASSUMPTION: the private DEVMODE structure only gets added to; // the fields that are in the DEVMODE never change only new fields get // added to the end. // memcpy(pOEMDevOut, pOEMDevIn, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize)); // // Re-fill in the size and version fields to indicated // that the DEVMODE is the current private DEVMODE version. // pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; // // If the plug-in is capable of recognizing multiple versions of it's // private DEVMODE data add custom handling here to support it. // } else { WARNING(DLLTEXT("Unknown DEVMODE signature, pOEMDMIn ignored.\r\n")); // // The private DEVMODE data is not something that this plug-in understands, // so use defaults. // pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; } return TRUE; }
HRESULT hrOEMDevMode(DWORD dwMode, POEMDMPARAM pOemDMParam) { POEMDEV pOEMDevIn; POEMDEV pOEMDevOut; // Verify parameters. if( (NULL == pOemDMParam) || ( (OEMDM_SIZE != dwMode) && (OEMDM_DEFAULT != dwMode) && (OEMDM_CONVERT != dwMode) && (OEMDM_MERGE != dwMode) ) ) { ERR(ERRORTEXT("DevMode() ERROR_INVALID_PARAMETER.\r\n")); VERBOSE(DLLTEXT("\tdwMode = %d, pOemDMParam = %#lx.\r\n"), dwMode, pOemDMParam); SetLastError(ERROR_INVALID_PARAMETER); return E_FAIL; } // Cast generic (i.e. PVOID) to OEM private devomode pointer type. pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn; pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut; switch(dwMode) { // //The Method should return the size of the memory allocation needed to store the UI plugin Private DEVMODE. // case OEMDM_SIZE: pOemDMParam->cbBufSize = sizeof(OEMDEV); break; // //Should fill the Private DEVMODE with the default values. // case OEMDM_DEFAULT: // //OEM_DMEXTRAHEADER Members // pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; // //Private members // pOEMDevOut->dwDriverData = 0; pOEMDevOut->dwAdvancedData = 0; VERBOSE(DLLTEXT("pOEMDevOut after setting default values:\r\n")); Dump(pOEMDevOut); break; // //The method should convert private DEVMODE members to the current version, if necessary. // case OEMDM_CONVERT: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut); break; // //The method should validate the information contained in private DEVMODE members and merge validated values into a private DEVMODE structure containing default values // case OEMDM_MERGE: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut); MakeOEMDevmodeValid(pOEMDevOut); break; } Dump(pOemDMParam); return S_OK; }