示例#1
0
static timezone_t
tzalloc(char const *val)
{
    static char **fakeenv;
    char **env = fakeenv;
    char *env0;
    if (! env) {
        char **e = environ;
        int to;

        while (*e++)
            continue;
        env = malloc(sumsize(sizeof *environ,
                             (e - environ) * sizeof *environ));
        if (! env) {
            err(EXIT_FAILURE, "malloc");
        }
        to = 1;
        for (e = environ; (env[to] = *e); e++)
            to += strncmp(*e, "TZ=", 3) != 0;
    }
    env0 = malloc(sumsize(sizeof "TZ=", strlen(val)));
    if (! env0) {
        err(EXIT_FAILURE, "malloc");
    }
    env[0] = strcat(strcpy(env0, "TZ="), val);
    environ = fakeenv = env;
    tzset();
    return env;
}
示例#2
0
文件: zdump.c 项目: ryo/netbsd-src
/* Return a time zone abbreviation.  If the abbreviation needs to be
   saved, use *BUF (of size *BUFALLOC) to save it, and return the
   abbreviation in the possibly-reallocated *BUF.  Otherwise, just
   return the abbreviation.  Get the abbreviation from TMP.
   Exit on memory allocation failure.  */
static char const *
saveabbr(char **buf, size_t *bufalloc, struct tm const *tmp)
{
	char const *ab = abbr(tmp);
	if (HAVE_LOCALTIME_RZ)
		return ab;
	else {
		size_t ablen = strlen(ab);
		if (*bufalloc <= ablen) {
			free(*buf);

			/* Make the new buffer at least twice as long as the
			   old, to avoid O(N**2) behavior on repeated calls.  */
			*bufalloc = sumsize(*bufalloc, ablen + 1);
			*buf = xmalloc(*bufalloc);
		}
		return strcpy(*buf, ab);
	}
}
示例#3
0
static bool ocl_integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, int sdepth, int sqdepth )
{
    bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;

    if ( _src.type() != CV_8UC1 || (!doubleSupport && (sdepth == CV_64F || sqdepth == CV_64F)) )
        return false;

    static const int tileSize = 16;

    String build_opt = format("-D SUM_SQUARE -D sumT=%s -D sumSQT=%s -D LOCAL_SUM_SIZE=%d%s",
                                ocl::typeToStr(sdepth), ocl::typeToStr(sqdepth),
                                tileSize,
                                doubleSupport ? " -D DOUBLE_SUPPORT" : "");

    ocl::Kernel kcols("integral_sum_cols", ocl::imgproc::integral_sum_oclsrc, build_opt);
    if (kcols.empty())
        return false;

    UMat src = _src.getUMat();
    Size src_size = src.size();
    Size bufsize(((src_size.height + tileSize - 1) / tileSize) * tileSize, ((src_size.width + tileSize - 1) / tileSize) * tileSize);
    UMat buf(bufsize, sdepth);
    UMat buf_sq(bufsize, sqdepth);
    kcols.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnlyNoSize(buf), ocl::KernelArg::WriteOnlyNoSize(buf_sq));
    size_t gt = src.cols, lt = tileSize;
    if (!kcols.run(1, &gt, &lt, false))
        return false;

    ocl::Kernel krows("integral_sum_rows", ocl::imgproc::integral_sum_oclsrc, build_opt);
    if (krows.empty())
        return false;

    Size sumsize(src_size.width + 1, src_size.height + 1);
    _sum.create(sumsize, sdepth);
    UMat sum = _sum.getUMat();
    _sqsum.create(sumsize, sqdepth);
    UMat sum_sq = _sqsum.getUMat();

    krows.args(ocl::KernelArg::ReadOnlyNoSize(buf), ocl::KernelArg::ReadOnlyNoSize(buf_sq), ocl::KernelArg::WriteOnly(sum), ocl::KernelArg::WriteOnlyNoSize(sum_sq));
    gt = src.rows;
    return krows.run(1, &gt, &lt, false);
}
示例#4
0
文件: zdump.c 项目: ryo/netbsd-src
/* Show a time transition.  */
static void
showtrans(char const *time_fmt, struct tm const *tm, time_t t, char const *ab,
	  char const *zone_name)
{
  if (!tm) {
    printf(tformat(), t);
    putchar('\n');
  } else {
    char stackbuf[1000];
    size_t size = sizeof stackbuf;
    char *buf = stackbuf;
    char *bufalloc = NULL;
    while (! istrftime(buf, size, time_fmt, tm, t, ab, zone_name)) {
      size = sumsize(size, size);
      free(bufalloc);
      buf = bufalloc = xmalloc(size);
    }
    puts(buf);
    free(bufalloc);
  }
}