From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexnader Kuleshov Newsgroups: gmane.emacs.bugs Subject: bug#24044: [PATCH] fileio.c: introduce make_temp_name_buf Date: Thu, 21 Jul 2016 16:02:21 +0600 Message-ID: <20160721100221.GA27186@localhost> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="AWniW0JNca5xppdA" X-Trace: ger.gmane.org 1469095415 10971 80.91.229.3 (21 Jul 2016 10:03:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Jul 2016 10:03:35 +0000 (UTC) To: 24044@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 21 12:03:25 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bQApA-0001tX-24 for geb-bug-gnu-emacs@m.gmane.org; Thu, 21 Jul 2016 12:03:24 +0200 Original-Received: from localhost ([::1]:39520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQAp9-000237-DR for geb-bug-gnu-emacs@m.gmane.org; Thu, 21 Jul 2016 06:03:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQAot-0001yk-V1 for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 06:03:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQAoo-00058f-37 for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 06:03:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQAon-00058I-WB for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 06:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bQAon-0000Lg-N4 for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 06:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alexnader Kuleshov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 Jul 2016 10:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24044 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14690953661305 (code B ref -1); Thu, 21 Jul 2016 10:03:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Jul 2016 10:02:46 +0000 Original-Received: from localhost ([127.0.0.1]:59307 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQAoY-0000Kz-AS for submit@debbugs.gnu.org; Thu, 21 Jul 2016 06:02:46 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39902) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQAoW-0000Kn-Ux for submit@debbugs.gnu.org; Thu, 21 Jul 2016 06:02:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQAoQ-00053i-Rq for submit@debbugs.gnu.org; Thu, 21 Jul 2016 06:02:39 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:37408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQAoQ-00053S-O9 for submit@debbugs.gnu.org; Thu, 21 Jul 2016 06:02:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQAoO-0001YW-B5 for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 06:02:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQAoI-000516-T3 for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 06:02:35 -0400 Original-Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]:32940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQAoI-00050s-Lp for bug-gnu-emacs@gnu.org; Thu, 21 Jul 2016 06:02:30 -0400 Original-Received: by mail-lf0-x22d.google.com with SMTP id b199so57255839lfe.0 for ; Thu, 21 Jul 2016 03:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=3AK3Wu0pYSwlNcLfhKuoIeBA6UqpPOe3WsFrfRYj2eA=; b=A+ipUm3BMT76hmdvSX2LHsZOdAv6WRPec8e7JJvY1OzW1WjoGsEjSL0tO8JcRJkhdt 1OxezMbiUqYaqqoLPV4ncWL6q7Mgd+ChzARfJN+FXf8LJPHDkgzqzUgDEjT0kPvZBAXk Xdv0p11+nrvQPX5SlgQ7yi5opN00tbNINcgiHvrxDBZ2AcVHVRDcSqFXHMO8JQvM51/3 cFBo0tAmeTZhw7LwsbSjbkdR5OgRflA0dkafWdsNQ955m/GW475OI5SNdhwGJfIUNJdx dIHEyqjpeWMRxquTwJleOHw3WRXLs06tBIdZZsyvsx+sDC+NA0XnQBzzZBXaPR89WaTG dyiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=3AK3Wu0pYSwlNcLfhKuoIeBA6UqpPOe3WsFrfRYj2eA=; b=U5kHDjd9k5Mlv80bhrxDgOpt+ui1wgpzhct4DOHyfmOv7ikJHVn9tTy9Bl0dvcpYy4 hnATBolTKuSYBW9/ddlEOKmNAszQKrYohxv34bdLMDkQxskHA42kdnPxbrYJJnxogH4a QnqZUGrOs/X/IAKF6e9BxeuTW4/gGewthzi7PziU6hFBkGlkJcHiTnBZxQuZEliuesp8 +3CUCUD5AO1oGyA8CSj8jWduMl5qgFlpsE9LnIsIZBJem/GmmHIiybeMW3FEVNyP7riz I2WC6Hci7eUJnjA7Lcgulf+YH68WjcTzVW6x/XNwU7UqJY9CDlkAJPMeJE4ByGAwy4UG s21Q== X-Gm-Message-State: ALyK8tLrKMAV7Id9kIJqkruN7tYbbD7sy0cIq/lNC6aER4yQlzn7EvGNvd+rUy+cezTnjw== X-Received: by 10.25.126.6 with SMTP id z6mr20951829lfc.155.1469095349516; Thu, 21 Jul 2016 03:02:29 -0700 (PDT) Original-Received: from localhost ([178.89.43.159]) by smtp.gmail.com with ESMTPSA id g69sm1479160lji.44.2016.07.21.03.02.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2016 03:02:28 -0700 (PDT) Content-Disposition: inline X-Operating-System: Linux X-Date: Thu Jul 21 15:32:33 +06 2016 User-Agent: Mutt/1.6.0-rc0 ((null)) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:121370 Archived-At: --AWniW0JNca5xppdA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, The make_temp_name function in a case when BASE64_P is true or when HAVE_LONG_FILE_NAMES is not defined builds buffer where first three characters is a PID in base64 encoding. This leads to some of code duplication. Attached patch introduces make_temp_name_buf() function which will do this functionality and allows to avoid code duplication. Thank you --AWniW0JNca5xppdA Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-fileio.c-introduce-make_temp_name_buf.patch" >From c58d13c750901e9f47c99dd2466e95dabb3730a1 Mon Sep 17 00:00:00 2001 From: Alexander Kuleshov Date: Wed, 20 Jul 2016 18:33:55 +0600 Subject: [PATCH] fileio.c: introduce make_temp_name_buf * src/fileio.c: New function - make_temp_name_buf. Use it in the make_temp_name() function. --- src/fileio.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index b1f9d3c..a23a5fc 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -620,6 +620,16 @@ static const char make_temp_name_tbl[64] = '4','5','6','7','8','9','-','_' }; +/* Add 3 characters in base64 encoding to the given buffer */ + +static char *make_temp_name_buf (char *buf, unsigned num) { + buf[0] = make_temp_name_tbl[num & 63], num >>= 6; + buf[1] = make_temp_name_tbl[num & 63], num >>= 6; + buf[2] = make_temp_name_tbl[num & 63], num >>= 6; + + return buf; +} + static unsigned make_temp_name_count, make_temp_name_count_initialized_p; /* Value is a temporary file name starting with PREFIX, a string. @@ -659,9 +669,7 @@ make_temp_name (Lisp_Object prefix, bool base64_p) if (base64_p) { - pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; - pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; - pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6; + make_temp_name_buf (pidbuf, pid); pidlen = 3; } else @@ -669,9 +677,7 @@ make_temp_name (Lisp_Object prefix, bool base64_p) #ifdef HAVE_LONG_FILE_NAMES pidlen = sprintf (pidbuf, "%"pMd, pid); #else - pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; - pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; - pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6; + make_temp_name_buf (pidbuf, pid); pidlen = 3; #endif } @@ -705,9 +711,7 @@ make_temp_name (Lisp_Object prefix, bool base64_p) { unsigned num = make_temp_name_count; - p[0] = make_temp_name_tbl[num & 63], num >>= 6; - p[1] = make_temp_name_tbl[num & 63], num >>= 6; - p[2] = make_temp_name_tbl[num & 63], num >>= 6; + make_temp_name_buf (p, num); /* Poor man's congruential RN generator. Replace with ++make_temp_name_count for debugging. */ -- 2.8.0.rc3.922.g2bcc146 --AWniW0JNca5xppdA--