本文整理汇总了C++中DIMOF函数的典型用法代码示例。如果您正苦于以下问题:C++ DIMOF函数的具体用法?C++ DIMOF怎么用?C++ DIMOF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DIMOF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_add_locinfov
LocInfo* parse_add_locinfov(Parse *p,char *filename, int lineno, char *line, char *tag, char *referrer, char *context_in,va_list args)
{
char buf[128];
char *ctxt = context_in;
LocInfo *l;
TIMER_START();
if(ctxt)
{
vsnprintf(buf,DIMOF(buf),ctxt,args);
buf[DIMOF(buf)-1] = 0;
ctxt = buf;
}
p->n_locs++;
l = ali_push(&p->locs);
l->tag = parse_find_add_str(p,tag);
l->referrer = parse_find_add_str(p,referrer);
l->context = parse_find_add_str(p,ctxt);
l->fname = parse_find_add_str(p,filename);
l->lineno = lineno;
l->line = parse_find_add_str(p,line);
TIMER_END(locinfo_timer);
return l;
}
示例2: _enable_mcast_address
/// Function to enable listening to a particular ethernet multicast address.
/// This is a highly non-portable function.
/// I wonder how you do this on BSD or Slowlaris?
FSTATIC gboolean
_enable_mcast_address(const char * addrstring ///<[in] multicast MAC address string suitable for giving to 'ip'
, const char * dev ///<[in] ethernet device
, gboolean enable) ///<[in] TRUE to enable, FALSE to disable
{
GSpawnFlags flags = G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_SEARCH_PATH;
gint exit_status;
const gchar* constargv [] =
{"ip", "maddress", (enable ? "add" : "delete"), addrstring, "dev", dev, NULL};
gchar* argv[DIMOF(constargv)];
unsigned j;
if (NULL == addrstring) {
return FALSE;
}
// This is really stupid and annoying - they have the wrong function prototype for g_spawn_sync...
for (j=0; j < DIMOF(argv); ++j) {
argv[j] = g_strdup(constargv[j]);
}
DEBUGMSG1("Running IP command %s %s %s %s %s %s", argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
if (!g_spawn_sync(NULL, argv, NULL, flags, NULL, NULL, NULL, NULL, &exit_status, NULL)) {
exit_status = 300;
}
for (j=0; j < DIMOF(argv); ++j) {
g_free(argv[j]);
argv[j] = NULL;
}
DEBUGMSG1("Previous IP command returned %d", exit_status);
return exit_status == 0;
}
示例3: DIMOF
bool CScriptEditView::OnFileSaveAs()
{
bool bRet = false;
TCHAR szFilter[256];
::ZeroMemory( szFilter, DIMOF(szFilter) );
int nChar = AtlLoadString( IDS_FILE_FILTER, szFilter, DIMOF(szFilter) );
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
CFileDialog dlg( FALSE, _T("*.txt"), m_szFilePath, dwFlags, szFilter );
if( dlg.DoModal() == IDOK )
{
ATLTRACE( _T("File path: %s\n"), dlg.m_ofn.lpstrFile );
bRet = SaveFile( dlg.m_szFileName );
if( bRet )
{
Init( dlg.m_szFileName, dlg.m_szFileTitle );
}
else
{
AtlMessageBox(
WtlGetMainWnd(),
IDS_WRITE_FILE_FAILED,
IDR_MAINFRAME,
MB_OK|MB_ICONERROR
);
}
}
return bRet;
}
示例4: Dialog_About_Create
/*
* Dialog_About_Create() [external]
*
* Called to create the about dialog. Returns the handle to the
* dialog created. This handle should only be used to check for
* errors during creation. Call Dialog_About_GetWindow() to get
* the handle for later use.
*/
HWND Dialog_About_Create(void)
{
PROPSHEETPAGE psp[2];
PROPSHEETHEADER psh;
int i;
for (i = 0; i < DIMOF(sps); i++)
{
INITSTRUCT(psp[i], TRUE);
psp[i].hInstance = g_hInstance;
}
psp[0].pszTemplate = MAKEINTRESOURCE(IDD_ABOUT_GENERAL);
psp[0].pfnDlgProc = About_General_DlgProc;
psp[1].pszTemplate = MAKEINTRESOURCE(IDD_ABOUT_INFOCREDZ);
psp[1].pfnDlgProc = About_InfoCredz_DlgProc;
INITSTRUCT(psh, TRUE);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_MODELESS | PSH_NOAPPLYNOW;
psh.hwndParent = Main_GetWindow();
psh.hInstance = Main_GetInstance();
psh.pszCaption = String_LoadString(IDS_TITLE_ABOUTDIALOG);
psh.nPages = DIMOF(sps);
psh.ppsp = (LPCPROPSHEETPAGE)&psp;
s_hwndDlgAbout = (HWND)PropertySheet(&psh);
return (s_hwndDlgAbout);
}
示例5: bind_and_listen
static int
bind_and_listen(struct addrinfo *addr)
{
int optval;
int fd;
int rc;
char buffer[256] = { 0, };
if (addr->ai_family == AF_INET6) {
struct sockaddr_in6 *addr_in = (struct sockaddr_in6 *)(void*)addr->ai_addr;
inet_ntop(addr->ai_family, &addr_in->sin6_addr, buffer, DIMOF(buffer));
} else {
struct sockaddr_in *addr_in = (struct sockaddr_in *)(void*)addr->ai_addr;
inet_ntop(addr->ai_family, &addr_in->sin_addr, buffer, DIMOF(buffer));
}
crm_trace("Attempting to bind on address %s", buffer);
fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (fd < 0) {
return -1;
}
/* reuse address */
optval = 1;
rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
if (rc < 0) {
crm_perror(LOG_INFO, "Couldn't allow the reuse of local addresses by our remote listener, bind address %s", buffer);
close(fd);
return -1;
}
if (addr->ai_family == AF_INET6) {
optval = 0;
rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval));
if (rc < 0) {
crm_perror(LOG_INFO, "Couldn't disable IPV6 only on address %s", buffer);
close(fd);
return -1;
}
}
if (bind(fd, addr->ai_addr, addr->ai_addrlen) != 0) {
close(fd);
return -1;
}
if (listen(fd, 10) == -1) {
crm_err("Can not start listen on address %s", buffer);
close(fd);
return -1;
}
crm_notice("Listening on address %s", buffer);
return fd;
}
示例6: abfile_test
int abfile_test()
{
File *fp;
char tmp[] = "abcdefghijklmnopqrstuvwxyz";
char tmp2[sizeof(tmp)];
struct Foo
{
int a;
char b[16];
} foos[3] = {
{1,"one"},
{2,"two"},
{3,"three"},
}, bars[DIMOF(foos)] = {0};
printf("abfile test...");
fp = abfopen("foo",File_W,FileType_Mem);
TEST(fp);
TEST(0==strcmp(fp->fn,"foo"));
TEST(1 == abfwrite(tmp,sizeof(tmp),1,fp));
TEST(sizeof(tmp) == abfread(tmp2,1,sizeof(tmp),fp));
TEST(0==memcmp(tmp,tmp2,sizeof(tmp)));
ZeroStruct(foos);
abfclose(fp);
fp = abfopen("bar",File_RW,FileType_Mem);
TEST(fp);
TEST(DIMOF(foos) == abfwrite(foos,sizeof(foos[0]),DIMOF(foos),fp));
TEST(DIMOF(bars) == abfread(bars,sizeof(bars[0]),DIMOF(bars),fp));
TEST(0==memcmp(foos,bars,sizeof(foos)));
ZeroStruct(foos);
abfclose(fp);
// read too many
fp = abfopen("bar",File_RW,FileType_Mem);
TEST(fp);
TEST(DIMOF(foos) == abfwrite(foos,sizeof(foos[0]),DIMOF(foos),fp));
TEST(DIMOF(bars) == abfread(bars,sizeof(bars[0]),DIMOF(bars)+1,fp));
TEST(0==memcmp(foos,bars,sizeof(foos)));
ZeroStruct(foos);
abfclose(fp);
// read too many 2: a little extra data
fp = abfopen("bar",File_RW,FileType_Mem);
TEST(fp);
TEST(1 == abfwrite(foos,sizeof(foos[0])+1,1,fp));
TEST(1 == abfread(bars,sizeof(bars[0]),DIMOF(bars)+1,fp));
TEST(0==memcmp(foos,bars,sizeof(foos)));
ZeroStruct(foos);
abfclose(fp);
printf("done.\n");
return 0;
}
示例7: core_uses_pid
static int
core_uses_pid(void)
{
const char * uses_pid_pathnames[] = {PROC_SYS_KERNEL_CORE_PID};
const char * corepats_pathnames[] = {PROC_SYS_KERNEL_CORE_PAT};
const char * goodpats [] = {"%t", "%p"};
int j;
for (j=0; j < DIMOF(corepats_pathnames); ++j) {
int fd;
char buf[BUF_MAX];
int rc;
int k;
if ((fd = open(corepats_pathnames[j], O_RDONLY)) < 0) {
continue;
}
memset(buf, 0, BUF_MAX);
rc = read(fd, buf, BUF_MAX - 1); /* Ensure it is always NULL terminated */
close(fd);
for (k=0; rc > 0 && k < DIMOF(goodpats); ++k) {
if (strstr(buf, goodpats[k]) != NULL) {
return 1;
}
}
break;
}
for (j=0; j < DIMOF(uses_pid_pathnames); ++j) {
int fd;
char buf[2];
int rc;
if ((fd = open(uses_pid_pathnames[j], O_RDONLY)) < 0) {
continue;
}
rc = read(fd, buf, sizeof(buf));
close(fd);
if (rc < 1) {
continue;
}
return (buf[0] == '1');
}
setenv(CHECKED_KERNEL_CORE_ENV, "1", TRUE);
return -1;
}
示例8: cl_set_all_coredump_signal_handlers
/*
* This function exists to allow security-sensitive programs
* to safely take core dumps. Such programs can't can't call
* cl_untaint_coredumps() alone - because it might cause a
* leak of confidential information - as information which should
* only be known by the "high-privilege" user id will be written
* into a core dump which is readable by the "low-privilege" user id.
* This is a bad thing.
*
* This function causes this program to call a special signal handler
* on receipt of any core dumping signal. This handler then does
* the following four things on receipt of a core dumping signal:
*
* 1) Set privileges to "maximum" on receipt of a signal
* 2) "untaint" themselves with regard to core dumping
* 3) set SIG_DFLT for the received signal
* 4) Kill themselves with the received core-dumping signal
*
* Any process *could* do this to get core dumps, but if your stack
* is screwed up, then the signal handler might not work.
* If you're core dumping because of a stack overflow, it certainly won't work.
*
* On the other hand, this function may work on some OSes that don't support
* prctl(2). This is an untested theory at this time...
*/
void
cl_set_all_coredump_signal_handlers(void)
{
static const int coresigs [] = {SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV
#ifdef SIGBUS
, SIGBUS
#endif
#ifdef SIGSYS
, SIGSYS
#endif
#ifdef SIGTRAP
, SIGTRAP
#endif
#ifdef SIGXCPU
, SIGXCPU
#endif
#ifdef SIGXFSZ
, SIGXFSZ
#endif
};
int j;
for (j=0; j < DIMOF(coresigs); ++j) {
cl_set_coredump_signal_handler(coresigs[j]);
}
}
示例9: ATLASSERT
LRESULT CScriptEditView::OnFindReplaceCmd( UINT, WPARAM, LPARAM lParam, BOOL& )
{
CFindReplaceDialog* pDlg = CFindReplaceDialog::GetNotifier(lParam);
if( pDlg == NULL )
{
::MessageBeep( (UINT)-1 );
return 1;
}
ATLASSERT( pDlg == m_pFindDlg );
if( pDlg->IsTerminating() )
{
m_pFindDlg = NULL;
return 0;
}
lstrcpyn( m_fro.StrToFind, pDlg->m_fr.lpstrFindWhat, DIMOF(m_fro.StrToFind) );
m_fro.bMatchCase = (pDlg->MatchCase() != FALSE);
m_fro.bWholeWord = (pDlg->MatchWholeWord() != FALSE);
if( pDlg->FindNext() )
{
if( !DoFindText() )
::MessageBeep( (UINT)-1 );
}
else if( pDlg->ReplaceCurrent() )
{
long nStart, nEnd;
GetSel( nStart, nEnd );
if( nStart != nEnd )
{
LPTSTR szFind = (LPTSTR)_alloca( (nEnd - nStart + 1) * sizeof(TCHAR) );
GetSelText( szFind );
int nRet;
if( m_fro.bMatchCase )
nRet = lstrcmp( szFind, m_fro.StrToFind );
else
nRet = lstrcmpi( szFind, m_fro.StrToFind );
if(nRet == 0)
ReplaceSel( pDlg->GetReplaceString(), TRUE );
}
if( !DoFindText() )
::MessageBeep( (UINT)-1 );
}
else if( pDlg->ReplaceAll() )
{
SetRedraw(FALSE);
CWaitCursor wait;
while( DoFindText(false) )
ReplaceSel( pDlg->GetReplaceString(), TRUE );
SetRedraw( TRUE );
Invalidate();
UpdateWindow();
}
return 0;
}
示例10: mh_test_is_match
int
mh_test_is_match(const char *pattern, const char *subject)
{
int erroroffset;
int ovector[OVECCOUNT];
const char *error;
pcre *re;
int rc;
re = pcre_compile(pattern,
0,
&error,
&erroroffset,
NULL);
if (re == NULL) {
return PCRE_ERROR_NULL;
}
rc = pcre_exec(
re,
NULL,
subject,
strlen(subject),
0,
0,
ovector,
DIMOF(ovector));
/* Since we only care about return code for now free the regex */
pcre_free(re);
return rc;
}
示例11: clist_set_sort_column
void clist_set_sort_column (GtkCList *clist, int column, struct clist_def *cldef) {
if (column == clist->sort_column) {
if (clist->sort_type == GTK_SORT_DESCENDING) {
cldef->cols[column].current_sort_mode = ++cldef->cols[column].current_sort_mode%DIMOF(cldef->cols[column].sort_mode);
if (cldef->cols[column].sort_mode[cldef->cols[column].current_sort_mode] == -1)
cldef->cols[column].current_sort_mode = 0;
}
gtk_clist_set_sort_type (clist, GTK_SORT_DESCENDING + GTK_SORT_ASCENDING - clist->sort_type);
}
else {
cldef->cols[column].current_sort_mode = 0;
clist_column_set_title (clist, cldef, FALSE);
gtk_clist_set_sort_column (clist, column);
}
debug (3, "%d %hhd", column, cldef->cols[column].current_sort_mode);
clist_column_set_title (clist, cldef, TRUE);
gtk_clist_sort (clist);
if (clist == server_clist) {
server_clist_selection_visible ();
}
}
示例12: cib_get_operation_id
int
cib_get_operation_id(const char *op, int *operation)
{
static GHashTable *operation_hash = NULL;
if (operation_hash == NULL) {
int lpc = 0;
int max_msg_types = DIMOF(cib_server_ops);
operation_hash = g_hash_table_new_full(crm_str_hash, g_str_equal, NULL, g_hash_destroy_str);
for (lpc = 1; lpc < max_msg_types; lpc++) {
/* coverity[returned_null] Ignore */
int *value = malloc(sizeof(int));
*value = lpc;
g_hash_table_insert(operation_hash, (gpointer) cib_server_ops[lpc].operation, value);
}
}
if (op != NULL) {
int *value = g_hash_table_lookup(operation_hash, op);
if (value) {
*operation = *value;
return pcmk_ok;
}
}
crm_err("Operation %s is not valid", op);
*operation = -1;
return -EINVAL;
}
示例13: cib_construct_reply
xmlNode *
cib_construct_reply(xmlNode * request, xmlNode * output, int rc)
{
int lpc = 0;
xmlNode *reply = NULL;
const char *name = NULL;
const char *value = NULL;
const char *names[] = {
F_CIB_OPERATION,
F_CIB_CALLID,
F_CIB_CLIENTID,
F_CIB_CALLOPTS
};
static int max = DIMOF(names);
crm_trace("Creating a basic reply");
reply = create_xml_node(NULL, "cib-reply");
crm_xml_add(reply, F_TYPE, T_CIB);
for (lpc = 0; lpc < max; lpc++) {
name = names[lpc];
value = crm_element_value(request, name);
crm_xml_add(reply, name, value);
}
crm_xml_add_int(reply, F_CIB_RC, rc);
if (output != NULL) {
crm_trace("Attaching reply output");
add_message_xml(reply, F_CIB_CALLDATA, output);
}
return reply;
}
示例14: pe_metadata
void
pe_metadata(void)
{
config_metadata("Policy Engine", "1.0",
"Policy Engine Options",
"This is a fake resource that details the options that can be configured for the Policy Engine.",
pe_opts, DIMOF(pe_opts));
}
示例15: get_cdp_type_string
/// Translate a CDP TLV type into a string.
/// @return pointer to a constant/static string describing the type of this TLV.
const char *
get_cdp_type_string(unsigned cdptype) ///< [in] CDP TLV type
{
if (cdptype < DIMOF(cdptypenames)) {
return cdptypenames[cdptype];
}
return "UNKNOWN";
}